开发者

How to filter a Font Character in php

I have an arial character giving me a headache. U+02DD turns into a question mark after I turn its document into a ph开发者_运维问答pquery object. What is an efficient method for removing the character in php by referring to it as 'U+02DD'?


You can use iconv() to convert character sets and strip invalid characters.

<?PHP
 /* This will convert ISO-8859-1 input to UTF-8 output and 
  * strip invalid characters
  */
 $output = iconv("ISO-8859-1", "UTF-8//IGNORE", $input);

 /* This will attempt to convert invalid characters to something
  * that looks approximately correct.
  */
 $output = iconv("ISO-8859-1", "UTF-8//TRANSLIT", $input);
?>

See the iconv() documentation at http://php.net/manual/en/function.iconv.php


Use preg_replace and do it like this:

$str = "your text with that character";

echo preg_replace("#\x{02DD}#u", "", $str); //EDIT: inserted the u tag for unicode

To refer to large unicode ranges, you can use preg_replace and specify the unicode character with \x{abcd} pattern. The second parameter is an empty string that. This will make preg_replace to replace your character with nothing, effectively removing it.


[EDIT] Another way:

Did you try doing htmlentities on it. As it's html-entity is &#733;, doing that OR replacing the character by &#733; may solve your issue too. Like this:

echo preg_replace("#\x{02DD}#u", "&#733;", $str);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜