- str_replace: documentation ( source)
- preg_replace: documentation ( source)
<?php
function convert_ascii($string)
{
// Replace Single Curly Quotes
$search[] = chr(226).chr(128).chr(152);
$replace[] = "'";
$search[] = chr(226).chr(128).chr(153);
$replace[] = "'";
// Replace Smart Double Curly Quotes
$search[] = chr(226).chr(128).chr(156);
$replace[] = '"';
$search[] = chr(226).chr(128).chr(157);
$replace[] = '"';
// Replace En Dash
$search[] = chr(226).chr(128).chr(147);
$replace[] = '--';
// Replace Em Dash
$search[] = chr(226).chr(128).chr(148);
$replace[] = '---';
// Replace Bullet
$search[] = chr(226).chr(128).chr(162);
$replace[] = '*';
// Replace Middle Dot
$search[] = chr(194).chr(183);
$replace[] = '*';
// Replace Ellipsis with three consecutive dots
$search[] = chr(226).chr(128).chr(166);
$replace[] = '...';
// Apply Replacements
$string = str_replace($search, $replace, $string);
// Remove any non-ASCII Characters
$string = preg_replace("/[^\x01-\x7F]/","", $string);
return $string;
}
$s = "Turn\u00a0things up with an invigorating concoction at Harry's!\u00a0Made using seven different spirits and topped with a can of redbull, get the exclusive Red Bull Trash Can at $18, or flash your Harry's SG App virtual membership card to enjoy it at $16.\u00a0\u00a0\u00a0Terms and conditionsPrices quoted are subject to prevailing government taxes and service charge.\u00a0Promotion is available till 4 September 2016 at all Harry's outlets except for Harry's Shenton Way and the ones within Changi Airport.\u00a0Harry'";
echo convert_ascii($s);