title: Converting Window-1252 to UTF-8 Issue
body: <p>I have created a function to convert the following text to UTF-8, as it appeared to be in Windows-1252 format, due to being copied to a database table from a Word Document. </p>
  
  <blockquote>
    <p>Testing weird characterâ€™s correction</p>
  </blockquote>
  
  <p>This seems to fix the dodgy <code>â€™</code> character. However i'm not getting � in the following:</p>
  
  <blockquote>
    <p>Devon�s most prominent dealerships</p>
  </blockquote>
  
  <p>When passing the following through the same function:</p>
  
  <blockquote>
    <p>Devon's most prominent dealerships</p>
  </blockquote>
  
  <p>Below is the code which does the converting:</p>
  
  <pre><code>function Windows1252ToUTF8($text) {
      return mb_convert_encoding($text, "Windows-1252", "UTF-8");
  }
  </code></pre>
  
  <p><strong>Edit:</strong>
  The database can't be changed due to holding thousands of custom records. I tried the below but the <code>mb_detect_encoding</code> thinks <code>characterâ€™s correction</code> is UTF-8. </p>
  
  <pre><code>function Windows1252ToUTF8($text) {
      if (mb_detect_encoding($text) == "UTF-8") {
          return $text;
      }
      return mb_convert_encoding($text, "Windows-1252", "UTF-8");
  }
  </code></pre>
  
  <p><strong>Edit 2:</strong>
  Just tried the example from the <a href="http://php.net/manual/en/function.mb-detect-encoding.php" rel="nofollow noreferrer">PHP Documentation</a>:</p>
  
  <pre><code>$str = 'áéóú'; // ISO-8859-1
  echo "&lt;pre&gt;";
  var_dump(mb_detect_encoding($str, 'UTF-8')); // 'UTF-8'
  var_dump(mb_detect_encoding($str, 'UTF-8', true)); // false
  echo "&lt;/pre&gt;";
  die();
  </code></pre>
  
  <p>but this simply outputs:</p>
  
  <blockquote>
    <p>string(5) "UTF-8"
    string(5) "UTF-8"</p>
  </blockquote>
  
  <p>So I can't even detect the encoding of the string :S </p>
  
  <p><strong>Edit 3:</strong>
  This seems to do the trick:</p>
  
  <pre><code>function Windows1252ToUTF8($text) {
      $badChars = [ "â", "á", "ú", "é", "ó" ];
      $match = preg_match("/[".join("",$badChars)."]/", $text);
      if ($match) {
          return mb_convert_encoding($text, "Windows-1252", "UTF-8");
      }
      return $text;
  }
  </code></pre>
  
  <p><strong>Edit 4:</strong>
  I have matched the hex values to their corresponding values. However when I get to the weird characters they don't appear to match.</p>
  
  <p><a href="https://i.stack.imgur.com/ewHhY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ewHhY.png" alt="enter image description here"></a></p>