Page 1 of 1
Replace "%20" with a space in a string!
Posted: Sun Feb 26, 2006 10:38 pm
by VKX
I have a string, lets say $username. I want to go through that string and replace all the "%20" with space so something like post%20a%20new%20topic would turn into post a new topic.
Just point me towards a function, and I'll see if I can do it from there

Posted: Sun Feb 26, 2006 10:42 pm
by nickman013
str_replace()
Its a pretty simple function, if you need help come back and post.
Code: Select all
$username = "post%20a%20new%20topic";
$new = str_replace("%20"," ", $username);
// $new would echo out to be "post a new topic"
Posted: Sun Feb 26, 2006 10:43 pm
by s.dot
you pretty much solved your own question in your topic title
replace .... string
str_replace()
or use
urldecode()
Posted: Mon Feb 27, 2006 12:12 am
by VKX
Works great, but what if I just want to delete a space all together? ie:
some var with spaces = somevarwithspaces
Posted: Mon Feb 27, 2006 12:14 am
by nickman013
Same thing pretty much.
Code: Select all
$blah = "this has spaces";
str_replace(" ", "", $blah);
//$blah will echo out with no spaces now
Posted: Mon Feb 27, 2006 12:15 am
by feyd
empty string for the second parameter...
Posted: Mon Feb 27, 2006 1:36 am
by VKX
Works great, thanks again guys.