jcadima
4/9/2016 - 5:43 PM

Understanding and working with UTF-8

Understanding and working with UTF-8

<?php
// check infophp() if mbstring is enabled
mb_internal_enconding('UTF-8') ;  // the character enconding we wish to work with
mb_http_output('UTF-8'); // html will output utf-8

$tring = 'international accents characters go here'; 

// any html following this is going to be utf-8
header('Content-Type: text/html; charset=utf-8') ;

?>
<!DOCTYPE html>
<html>
  <head>
    <title></title>

  </head>
  <body>
  
<strong>This will may or may not display the string correctly and also the count</strong>
<p>Upper: <?php echo strtoupper($string) ; ?> </p>
<p>Count: <?php echo strlen($string) ; ?>  </p>

  
<strong>This will display the string correctly and also the count<br>Note we prepend mb_  to the php functions</strong>
<p>Upper: <?php echo mb_strtoupper($string) ; ?> </p>
<p>Count: <?php echo mb_strlen($string) ; ?>  </p>


  </body>
</html>