Skip to content

Instantly share code, notes, and snippets.

@aa21
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aa21/29ce1c33459de834aa4e to your computer and use it in GitHub Desktop.
Save aa21/29ce1c33459de834aa4e to your computer and use it in GitHub Desktop.
//source: http://www.toao.net/48-replacing-smart-quotes-and-em-dashes-in-mysql
//By Mango, March 5th, 2009
//clean charset
function c($text){
// First, replace UTF-8 characters.
$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("'", "'", '"', '"', '-', '--', '...'),
$text
);
// 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment