How to use UTF-8
characters in a PHP-script?
I know there is an escape character to interpret the next two characters as UTF-8
. That escape is \s
. So \xFF
works, which will represent 'ÿ
'.
But now I want to remove zero-width spaces (U+200B
) from a string. How to do that? Can I开发者_Python百科 use the function str_replace()
, or maybe preg_replace()
?
Thanks in advance.
This worked for me:
$str = str_replace("\xe2\x80\x8b", '', $str);
Sources:
- http://www.fileformat.info/info/unicode/char/200b/index.htm
- http://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128&utf8=string-literal
You may want to try mb_ereg_replace()
or iconv()
with str_replace.
http://www.php.net/manual/en/function.mb-ereg-replace.php
http://hu.php.net/manual/en/function.iconv.php
Remove zero-width space:
$str = str_replace(chr(13), "", $str);
精彩评论