Replace MS Smart Quotes In PHP


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?
  2. $string="Steve�s fix for MicroSux �Smart Quotes�";
  3. print "Original |$string|<br>";
  4. echo "Final " . fix_ms_smart_quotes($string) ."<br>";
  5.  
  6. function fix_ms_smart_quotes($string) {
  7. $text = str_replace(
  8. array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
  9. array("'", "'", '"', '"', '-', '--', '...'),
  10. $string);
  11. // Next, replace their Windows-1252 equivalents.
  12. $text = str_replace(
  13. array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
  14. array("'", "'", '"', '"', '-', '--', '...'),
  15. $text);
  16. return $text;
  17. }
  18. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.