how to check if a string is utf8, any is_utf8() function?

gnosis.kv - May 27, 2008 - 15:10

Hi,

What's the proper way to check if a given string is utf8? then based on this checking, we will decide to run drupal_convert_to_utf8 to the string or not?

so, i want some code snip, like

<?php
if(!is_utf8($string)){
  
$string = drupal_convert_to_utf8($string);
}
?>

but, i dont know how to do the is_utf8 function.

any advise?

thanks a lot in advance

...

mooffie - May 29, 2008 - 09:26

See http://php.net/mb_check_encoding.

(Notes: 1. plain ascii too is valid utf-8. 2. I don't know what's the probability that a random string in a valid encoding which isn't utf-8 will be validated as such, but it's probably very very low; it's better to run is_utf8() on the whole data and not on individual strings.)

thanks very much..

gnosis.kv - June 3, 2008 - 03:52

thanks very much..

 
 

Drupal is a registered trademark of Dries Buytaert.