I have a HTML string containing £ signs, for some reason i'm not able to replace them. I'm assuming this is an encoding issue although i can't work out how. The site is using ISO-8859-1 for its encoding
$str = '<span class="price">£89.99</span>';
var_dump(mb_detect_encoding($str, 'ISO-8859-1', true)); // outputs ISO-8859-1
echo str_replace(array("£","£"),"",$str); // nothing is removed
echo htmlentities($str); // the entire string is converted, including £ to £
Any ideas?
EDIT
should have pointed out i want to replace the £ with £
; - i had temporarily added £
to the array of items to replace in case it had already been converted
Just a guess but could it be that even thou your website outputs in ISO-8859-1 encoding, your actual *.php files are saved as utf-8? i don't think that str_replace works correctly with utf-8 strings. To test it try:
str_replace(utf8_decode("£"),"£",utf8_decode($str));
Yeah, if this works then your *.php files are saved in utf-8 encoding. This means all the string constants are in utf-8. It's probably worth switching default encoding in your IDE to ISO-8859-1
html_entity_decode(str_replace("£", "", htmlentities($str)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With