Return to Snippet

Revision: 18849
at October 9, 2009 18:23 by SteveMcDaniel


Updated Code
<?
$string="Steve�s fix for MicroSux �Smart Quotes�";
print "Original |$string|<br>";
echo "Final " . fix_ms_smart_quotes($string) ."<br>";

function fix_ms_smart_quotes($string) {
	$text = str_replace(
	 array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
	 array("'", "'", '"', '"', '-', '--', '...'),
	 $string);
	// Next, replace their Windows-1252 equivalents.
	 $text = str_replace(
	 array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
	 array("'", "'", '"', '"', '-', '--', '...'),
	 $text);
	 return $text;
}
?>

Revision: 18848
at October 9, 2009 18:16 by SteveMcDaniel


Initial Code
<?
$string="Steve’s fix for MicroSux “Smart Quotes”";
print "Original |$string|<br>";
echo "Final " . fix_ms_smart_quotes($string) ."<br>";

function fix_ms_smart_quotes($string) {
	$text = str_replace(
	 array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
	 array("'", "'", '"', '"', '-', '--', '...'),
	 $string);
	// Next, replace their Windows-1252 equivalents.
	 $text = str_replace(
	 array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
	 array("'", "'", '"', '"', '-', '--', '...'),
	 $text);
	 return $text;
}
?>

Initial URL

                                

Initial Description

                                

Initial Title
Replace MS Smart Quotes In PHP

Initial Tags
php, replace

Initial Language
PHP