Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * An array of characters that we want to convert
- */
- function get_bad_characters() {
- static $find;
- if ( ! is_array($find) ) {
- $find = array();
- $find[] = '“'; // left side double smart quote
- $find[] = 'â€'; // right side double smart quote
- $find[] = '‘'; // left side single smart quote
- $find[] = '’'; // right side single smart quote
- $find[] = '…'; // elipsis
- $find[] = '—'; // em dash
- $find[] = '–'; // en dash
- $find[] = '’'; // quote mark
- $find[] = 'â€"'; // ndash I think
- $find[] = 'â€Â'; // close right double quote
- $find[] = '·'; // small filled dot or small black bullet
- $find[] = '"¢'; // regular bullet
- $find[] = '�'; // apostrophe
- }
- return $find;
- }
- /**
- * An array of replacement characters that map in order to the ones from bad_characters()
- */
- function get_replacements() {
- static $replacements;
- if ( ! is_array($replacements) ) {
- $replacements = array();
- $replacements[] = '"';
- $replacements[] = '"';
- $replacements[] = "'";
- $replacements[] = "'";
- $replacements[] = "...";
- $replacements[] = "-";
- $replacements[] = "-";
- $replacements[] = "'";
- $replacements[] = "–";
- $replacements[] = '"';
- $replacements[] = "·";
- $replacements[] = "•";
- $replacements[] = "'";
- }
- return $replacements;
- }
- function fix_characters($string) {
- $string = str_replace(get_bad_characters(), get_replacements(), $string);
- return $string;
- }
- function fix_characters_simpler($string) {
- $map = array(
- '“' => '"',
- 'â€' => '"',
- '‘' => "'",
- '’' => "'",
- '…' => "...",
- '—' => "-",
- '–' => "-",
- '’' => "'",
- 'â€"' => "–",
- 'â€Â' => '"',
- '·' => "·",
- '"¢' => "•",
- '�' => "'",
- );
- return str_replace(array_keys($map), array_values($map), $string);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement