duan0821 2011-10-15 05:20
浏览 12
已采纳

提取与$ _GET [duplicate]结果相同的URL字符串

This question already has an answer here:

Ok, so I have a string like so:

index.php?page=test2;sa=blah

And I need only to grab what gets returned using $_GET['page'], so it will return, test2 in this case. BUT page MUST be defined DIRECTLY after index.php? before it can return an actual string. How do I do this? I just need the same results returned from a $_GET for the page variable. I can also have just this:

index.php?page=blah

Should return blah

or this:

index.php?page=anything&sa=blah

Returns anything

or this:

index.php?action=blah;page=2

Returns empty string, cause this is NOT directly after index.php?

or basically any url, but it needs to grab the variable of page if it exists, only after index.php?. And sometimes page might not even exist at all, in this case, an empty string should be returned.

How can I do this? I am not browsing to the URL in my browser, so, don't think $_GET will work, but it needs to simulate and return the EXACT same results that $_GET will return in the browser, but only if page is defined directly after index.php?

</div>
  • 写回答

3条回答 默认 最新

  • dqotv26286 2011-10-15 05:31
    关注

    Please use following code:

    function get($name, $url) {
       $src = parse_url($url);
       $src = $src['query'];
       parse_str($src, $tag);
       return $tag[$name];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳