0

我正在尝试将 Url 的最后 2 个字符插入到我的数据库中。当我每次插入时,它都需要一些数字,例如“2147483647”。如何插入正确的最后 2 个 Url 字符。'$array = json_decode(stripslashes($_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();

} 回声 json_encode($array);'

4

1 回答 1

0

尝试子串

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


$last2 = substring($url,-2);
于 2012-08-09T14:25:06.543 回答