Reputation: 23
I wish to remove white space from a string. The string would have ben urlencoded()
prior, so I also wish to remove %20
too. I can do this using two separate functions, but how do i do this with one function?
$string = str_replace("%20","",$string);
$string = str_replace(" ","",$string);
Upvotes: 0
Views: 576
Reputation: 89574
Don't use a regex for that but strtr:
$result = strtr($str, array('%20'=>'', ' '=>''));
Upvotes: 1
Reputation: 174766
You could use preg_replace
function.
preg_replace('~%20| ~', "", $string)
Upvotes: 1