title: Smart Quotes Elimination With Japanese Characters
body: <p>Having smart quotes in a string was causing issues with storage in MYSQL and subsequent rendering. So I have a php function that replaces smart quotes with regular quotes. </p>
  
  <p>However, when the string has Japanese characters, it converts some characters into a combination of non-printable character and a regular quote. </p>
  
  <p>I am assuming that it is due to way the foreign language characters are encoded and there is a partial match with the smart-quote binary encoding causing this issue.   </p>
  
  <p>Here is a script that demonstrates the problem:</p>
  
  <pre><code>  &lt;?php
    function convert_smart_quotes($string)
    {
        $search = array(chr(145),
        chr(146),
        chr(147),
        chr(148));
  
        $replace = array("'",
         "'",
         '"',
         '"');
  
        return str_replace($search, $replace, $string);
    }
   $input_str = "すっぴん美人になるためにやってはいけない「３スギ」とは？";
   $output_str = convert_smart_quotes($input_str);
   echo $output_str;
  </code></pre>
  
  <p>Basically, I want this function to work when it is latin characters based language string. At the same time, if it is a foreign language, I don't want it to mess up the string. Since there is no simple way to detect languages in php, how do I achieve this?</p>