URL地址类型:http://localhost/?action-channel-name-tuku-id-1我想获取 "-id-"  后面  1 这个值...并帮把存到一个变量中去..

解决方案 »

  1.   

    <?PHP
    $url="http://localhost/?action-channel-name-tuku-id-1";
    $arr = parse_url($url);
    $p = $arr['query'];
    $value = preg_match('/.*\-id\-?(\d)$/', $p, $match);
    echo $value[1];
    ?>
      

  2.   

    LZ你这
    http://localhost/?action-channel-name-tuku-id-1 
    是什么?是不是地址重写后的地址啊?要是的话就得找到他的真实地址,然后接收ID
      

  3.   

    最后一句错了,match出来的值应该在$match中,最后一句改为
    echo $match[1];
      

  4.   


    这个就跟康盛的supesite里的一样。http://localhost/?action-channel-name-tuku-id-1
    其实就是http://localhost/index.php?action-channel-name-tuku-id-1这里在index.php里用$string = $_SERVER['QUERY_STRING'] 就可以取得action-channel-name-tuku-id-1
    这时就要自己手动对URL参数进行分组并判断了。
    比如用字符串切割等。。
      

  5.   

    小弟刚学PHP..什么切割,怎么切割实在不懂..要例子吗?
      

  6.   

    $s = 'action-channel-name-tuku-id-1';
    $id = substr(strstr($s,'-id-'),4);
    echo $id;作为通式
    $ar = split('-', $s);
    for($i=0; $i<count($ar); $i+=2)
      ${$ar[i]} = $ar[$i+1];echo $id;