Posted By

fackz on 06/29/15


Tagged

utf8 detect convert utf-8


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

fackz


Detect and convert utf-8 on string


 / Published in: PHP
 

I can't say I can rely on mbdetectencoding(). Had some freaky false positives a while back. The following code will detect when you need to enconde or decode it.

  1. if (preg_match('!!u', $string))
  2. {
  3. // this is utf-8
  4. }
  5. else
  6. {
  7. // definitely not utf-8
  8. }

Report this snippet  

You need to login to post a comment.