Re: str_replace not working?
Did you look at the source code? an & in HTML is viewed as &. It may have changed it but it wouldn't be noticable to you.
Re: str_replace not working?
try preg_replace ( mixed pattern, mixed replacement, mixed subject)
ex:
PHP Code:
<?php
$a = "http://somesite.com/index.cfm?&user=24706091";
$b = preg_replace("&","&",$a);
echo $b;
?>
Re: str_replace not working?
Quote:
Originally Posted by Jmacp
Must be missing something here but str_replace isnt working for me, take this simple example,
PHP Code:
<?php
$a = "http://somesite.com/index.cfm?&user=24706091";
$b = str_replace("&","&",$a);
echo $b;
?>
Result is still the original url whereas it should be,
http://somesite.com/index.cfm?&user=24706091
:confused:
That code works fine, like kasracer said check the source. You should also be careful when creating url with & inside, it can cause some things you didnt expect to happen, use urlencode to make sure that you get the exact values you want from the query stirng
Re: str_replace not working?
Its also worth noting that there is a function. htmlspecialchars() which converts all HTML meta characters to their entity equivilents.
The replacement you made inserts a literal ampersand into the query string. Like John has pointed out, you need to use urlencode() on this instead of escaping it as html, a URL encoded string is valid in an HTML attribute string and shouldn't need further escaping.