[英]PHP - str_replace not working with URL variable string
I am building URL variables into another variable named '$url' below: 我在下面将URL变量构建到另一个名为“ $ url”的变量中:
$url = "page2.php?";
$url .= "&Keyword=$keyword";
$shopByStore = $_GET["store"];
if (!empty($shopByStore)) {
$url .= "&store=$shopByStore";
}
// plus many more variables built into the URL variable based on user input.
Under certain conditions, I will need to remove portions of the $url variable string. 在某些情况下,我将需要删除$ url变量字符串的某些部分。 The str_replace method is not removing the portion of the string in the $url variable placed in the href tags.
str_replace方法不会删除放置在href标记中的$ url变量中的字符串部分。 The value for '&store' is appearing in the source code and in the actual link in the browser.
“&store”的值出现在源代码和浏览器的实际链接中。
if ($foo == "certain_condition) {
str_replace("&store=$shopByStore", "", $url);
?>
<a href="<?php echo $url; ?>">Clear</a><br>
<?php
}
Any advice is greatly appreciated!!! 任何意见是极大的赞赏!!!
str_replace
returns the modified string, it does not alter the string that you pass to it. str_replace
返回修改后的字符串,它不会更改传递给它的字符串。
Try: $url = str_replace("&store=$shopByStore", "", $url);
试试:
$url = str_replace("&store=$shopByStore", "", $url);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.