I have a string (taken from a MySQL database if it makes any difference) which looks normal enough:
Manufacture: <a href="http://www.x.com/">Blah</a>
The problem is that the space between Manufacture:
and the <a>
tag has a charcode of 194, not 32 as I would expect.
This is causing a preg_match
with the following pattern to fail (please ignore the attempts to parse HTML with regex, I know it's not a good idea but this particular dataset is predictable enough to get away with it):
/Manufacture: *(<a[^>]*>([A-Za-z- 0-9]+)<\/a>)/i
If I replace the rogue space with a normal space character in a text editor and try again, the expression matches as expected, but I need to alter it programatically.
I tried str_replace
:
$text = str_replace(chr(194), ' ', $text);
But the preg_match
still fails. I then tried preg_replace
:
$text = preg_replace('/[\xC2]/', ' ', $text);
But that doesn't work either, even though running that same pattern through preg_match
does contain the expected match.
Does anyone have any ideas?