How to replace a parameter in sitring?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bizzy
Forum Newbie
Posts: 10
Joined: Mon Apr 16, 2007 1:15 pm

How to replace a parameter in sitring?

Post by Bizzy »

Hey guys, it might be dumb question for you, but huge problem for me.

If I have for example:

Code: Select all

$newBrand = "nike";
$question = "/?brand=adidas&size=M";
How should I set new "brand" and get $question in same format?

Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You could use something like preg_replace() to replace everything between 'brand=' and '&'. Or you could explode() on '&' and then '=' and then reassemble. There are probably a couple other ways to do it as well.
(#10850)
Post Reply