Click to See Complete Forum and Search --> : using str_replace


tall1
01-12-2006, 10:27 PM
ok what is wrong with this code?

$looking_for_url = str_replace(" ", "_", $looking_for);


I am trying to replace all spaces in variable "$looking_for" with an underscore.

e.g. $looking_for = "I am Happy!"

I want it to be: I_am_Happy!

NogDog
01-12-2006, 10:40 PM
Works fine for me. Maybe a typo in a variable name somewhere else?

Also, if the idea is to make the string usable as part of the query string of a URL, you could leave the spaces as is and use urlencode() (http://www.php.net/urlencode) instead.