Possible Duplicate:
How to replace � in a string
I am reading data from an XML sheet coming out of a database. In the raw output I am coming accross this character "�" which is the UTF-8 string meaning "�". Doing a simple search and remove with str_replace does not do the trick when searching for "�" or "�". Is there any other way to remove this character from a string?
UPDATE:
For reference this is the function that is cleaning up strings for me.
function db_utf8_convert($str)
{
$convmap = array(0x80, 0x10ffff, 0, 0xffffff);
return preg_replace('/\x{EF}\x{BF}\x{BD}/u', '', mb_encode_numericentity($str, $convmap, "UTF-8"));
}
You can do this:
$str = 'UTF-8 string meaning "�"';
echo preg_replace('/\x{EF}\x{BF}\x{BD}/u', '', iconv(mb_detect_encoding($str), 'UTF-8', $str));
Output: UTF-8 string meaning ""
You could do something similar to this:
<?php
$string = "asd fsa fsaf sf � asdfasdfs";
echo preg_replace("/[^\p{Latin} ]/u", "", $string);
Check out this script for more character matches:
http://www.regular-expressions.info/unicode.html#script
EDIT
I did find, this, people says it works, you could give it a try:
<?php
function removeBOM($str=""){
if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
$str=substr($str, 3);
}
return $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