Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use UTF-8 characters in a PHP-script?

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 use the function str_replace(), or maybe preg_replace()?

Thanks in advance.

like image 562
MC Emperor Avatar asked Feb 24 '23 20:02

MC Emperor


1 Answers

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
like image 140
seriousdev Avatar answered Mar 05 '23 03:03

seriousdev