문제

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?

도움이 되었습니까?

해결책

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

다른 팁

You might prefer using the url_decode() function.

http://uk1.php.net/url_decode

That said, your code looks fine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top