繁体   English   中英

使用strpos的strstr无法正常工作(PHP)

[英]strstr with strpos not working (PHP)

我正在尝试在某些字符后修剪URL的末尾。 我的URL在SESSION变量中。

if(strpos($_SESSION['LP'],'ordrer'))
         {
            $Order1 = $_SESSION['LP'];
            $Order2 = strpos($Order1, "ordrer");
            $Order = substr($Order1,0,$Order2);
            //$Order1 = $Order1(explode('ordrer', $Order1);

         }

我首先将URL放入变量中。 然后使用strpos查找其中是否包含“ ordrer”,然后在“ ordrer”之后剪切我的URL的末尾。 基本上,我有/Dossiers.php?ordrer=Numero或/Dossiers.php?ordrer=Status,我想拥有/Dossiers.php? 但是我对URL没有任何作用,为什么? 还尝试了explode(),结果相同。 谢谢

我看不到您的代码有什么问题-$ Order应该包含您的URL。 我已经测试了以下代码,将您的URL放入$ url。 可能是$ _SESSION ['LP']为空吗?

我还使用explode在底部为您创建了第二个版本。

$url = "/Dossiers.php?ordrer=Numero";

//Your version
if (strpos($url,'ordrer'))
     {
        $Order1 = $url;
        $Order2 = strpos($Order1, "ordrer");
        $Order = substr($Order1,0,$Order2);
        echo $Order; // the first part, including ?
     }

//If there is no question mark, you'll just get the whole string
$parts = explode("?", $url);
$Order = $parts[0];
echo $Order; //The first part, excluding ?

编辑:附加的想法-您的问题是“ ordrer”应该是“ order”吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM