在数据库 php 中插入 URL 最后 2 个字符


Insert Url last 2 characters in database php

我正在尝试将 Url 的最后 2 个字符插入我的数据库。当我每次插入时,它都需要一些数字,例如"2147483647"。如何插入 URL 的正确最后 2 个字符。 '$array = json_decode(条形斜杠($_POST['data']));

for($i = 0, $l = sizeof($array); $i <$l; $i++){ $obj = $array[$i];

if($obj->{'leaf'} == true){
    $leaf = 1;
} else{
    $leaf = 0;
}
if($obj->{'parentId'} == null){
    $parentID = 'null'; 
} else{
    $parentID = $obj->{'parentId'};
}
if($obj->{'Duration'}==''){
    $duration = 0;
} else{
    $duration = $obj->{'Duration'};
}


$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$gantt_id = substr(strrchr($url, '='), 1);
/*if($obj->{'gantt_id'}==null){
    $gantt_id = 0;
} else{
    $gantt_id = $obj->{'gantt_id'};
}
*/
$q = 'INSERT INTO j_gantt_tasks SET Name = "'.$obj->{'Name'}.'", StartDate = "'.$obj->{'StartDate'}.'", EndDate = "'.$obj->{'EndDate'}.'",
      Duration = "'.$obj->{'Duration'}.'", DurationUnit = "'.$obj->{'DurationUnit'}.'", PercentDone = "'.$obj->{'PercentDone'}.'", Cls = "'.$obj->{'Cls'}.'", gantt_id="'.$gantt_id.'",
      parentId = "'.$obj->{'parentId'}.'"';
$r = mysql_query($q);
if(!$r){
    echo db_error($q);
}
$obj->{'id'} = mysql_insert_id();

}echo json_encode($array);'

尝试子字符串

$url = (!empty($_SERVER['HTTPS'])) ?
     "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : 
     "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

$last2 = substring($url,-2);