Saturday, September 13, 2014

Convert utf8-characters and back in PHP

Set meta tag in head as

  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

use the link http://www.i18nqa.com/debug/utf8-debug.html to replace the symbols character you want.

then use str_replace like
<?php
$content='Kinsa – World’s Smartest Thermometer';
$find = array('“', '’', '…', '—', '–', '‘', 'é', 'Â', '•', 'Ëœ', 'â€'); // en dash
$replace = array('“', '’', '…', '—', '–', '‘', 'é', '', '•', '˜', '”');
echo $content = str_replace($find, $replace, $content);
output Kinsa – World’s Smartest Thermometer
?>

No comments:

Post a Comment