簡體   English   中英

PHP-str_replace無法使用URL變量字符串

[英]PHP - str_replace not working with URL variable string

我在下面將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.

在某些情況下,我將需要刪除$ url變量字符串的某些部分。 str_replace方法不會刪除放置在href標記中的$ url變量中的字符串部分。 “&store”的值出現在源代碼和瀏覽器的實際鏈接中。

if ($foo == "certain_condition) {
str_replace("&store=$shopByStore", "", $url);
?>
<a href="<?php echo $url; ?>">Clear</a><br>
<?php
}

任何意見是極大的贊賞!!!

str_replace返回修改后的字符串,它不會更改傳遞給它的字符串。

試試: $url = str_replace("&store=$shopByStore", "", $url);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM