Question

I did a URL encode and spaces have been replaced by +.

I am trying to replace the + with %20 using str replace.

$x = str_replace('+', '%20', $name);

What is the syntax error here?

Was it helpful?

Solution

There is no errors in the code you posted so your error must lie another place in your code

<?php
$name = "potato+tomato";
$x = str_replace('+', '%20', $name);
echo $x;

Output: potato%20tomato

OTHER TIPS

You might prefer using the url_decode() function.

http://uk1.php.net/url_decode

That said, your code looks fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top