0

I am building URL variables into another variable named '$url' below:

$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. The str_replace method is not removing the portion of the string in the $url variable placed in the href tags. The value for '&store' is appearing in the source code and in the actual link in the browser.

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

Any advice is greatly appreciated!!!

2
  • Why don't you add the variable under anything other than "certain conditions" instead of adding then removing it again? Commented Apr 2, 2014 at 1:43
  • There's a typo in your pseudo if statement (missing the closing "). Commented Apr 2, 2014 at 1:46

1 Answer 1

3

str_replace returns the modified string, it does not alter the string that you pass to it.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.