Frage

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?

War es hilfreich?

Lösung

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

Andere Tipps

You might prefer using the url_decode() function.

http://uk1.php.net/url_decode

That said, your code looks fine.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top