dongou3158 2015-11-13 05:20
浏览 72

无法从php中的url检索括号值?

I am having a problem a problem with retrieving parenthesis value from url. I am developing a PHP project using CodeIgniter Framework.

I have a mvc url format like this - http://localhost/controller/action/id/name

Then I passed the value like this - http://localhost/controller/action/2/test%20(test)

And like this as well - Then I passed the value like this:

http://localhost/controller/action/2/test+(test)

So my action function is like this with parameters-

function action($id,$name)
{
   $name = urldecode($name)
   //I find the index of start "t"
   echo strpos($name,'t'); //this is working find
   echo strpos($name,'('); // this is outputing nothing
   echo $name; // this is outputing test (test)
}

What is the problem ? Why cannot I find index of "(". Actually I and retrieving record from database using that value. But parenthesis is not working well with php. I showing output correctly. But cannot find index of it.

  • 写回答

3条回答 默认 最新

  • douhe8981 2015-11-13 05:34
    关注

    Try this

    <?php
    $url = 'localhost/melomap_music/singers/details/760/test%20(test)';
    $string = urldecode($url);
    $pattern1 = '/[)]/';
    $pattern2 = '/[(]/';
    preg_match($pattern1, $string, $matches, PREG_OFFSET_CAPTURE);
    preg_match($pattern2, $string, $matches2, PREG_OFFSET_CAPTURE);
    $start = $matches2[0][1]; //49
    $end = $matches[0][1]; //54
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于九十度混合耦合器信号分析问题
  • ¥15 Cesm如何关闭不用的模块呢
  • ¥15 vue2两层数据导出为excle
  • ¥15 有人能帮我做一下这个项目吗
  • ¥15 网络上传速率比下载速率高
  • ¥15 (标签-游戏|关键词-网页游戏)
  • ¥15 这个咋搞🥹可能需要手把手教
  • ¥15 接口和关键字的问题,多选
  • ¥15 yolov5s模型下载就卡住,没有运行结果
  • ¥20 androidstudio工具问题