Okay, I need a REALLY goofy PHP based character search and replace I need to do. I need PHP to look at a string and replace all instances of the hexadecimal character 'AO' with the hexadecimal character '20'. Both of these hex characters look like a space to you and I but computers see these as two different characters and it is playing havoc in Internet Explorer with a search function I use on my site. No matter what I try I can't seem to get PHP to find the hex character 'AO' and then replace it with '20'. Any help would be greatly appreciated. This really is a bizarre problem.
I don't know if it will work cause I don't understand your problem but it doesn't hurt to try it out: $oldstring = "AOAOAO AO"; $newstring = str_replace("AO", "20", $oldstring); echo $newstring; // this would return: 202020 20 Code (markup):
I think what you really want to replace is "\xA0". You might need to use preg_replace('/\xA0/', ' ', $input) instead. Cryo.
Cryogenius has the right answer. - Thanks. danielbruzual, your answer only works for replacing those characters if they occur as real characters. My problem was that we were looking at two different hexadecimal codes for essentially the same character (in this case a space). I ended up having to add the following code $strLink= preg_replace("/\s/"," ",$strLink); $strLink= preg_replace("/\xa0/"," ",$strLink); There were some other replacements I had to do, and I still have to monitor for any bad side effects but I think I'm going in the right direction.
You dont need to use regular expressions. You can use str_replace itself. Like this: str_replace("\xAO", "\x20", $oldstring); Thomas