title: Different Variants of UTF-8 Comma? [，] [,] - CURL Response for MySQL Data
body: <p>Prepping a Curl Response for particular data to be inserted into a MySQL Table.</p>
  
  <p>Noticed some special characters in the saved data for certain URL's.</p>
  
  <pre><code>$curldata = curl_exec($curl);
  $encoding = mb_detect_encoding($curldata);
  </code></pre>
  
  <p>brought back <code>ASCII</code> encoding.</p>
  
  <p>Okay, don't want that.</p>
  
  <p>The tables in my database are an <code>InnoDB</code> type with a <code>utf8mb4_unicode_ci</code> collation.</p>
  
  <p>Added this to my curl options:</p>
  
  <pre><code>curl_setopt($curl, CURLOPT_ENCODING, 1);
  </code></pre>
  
  <p>And an <code>iconv</code> function based on the above <code>mb_detect_encoding</code> / <code>$encoding</code> variable upon save.</p>
  
  <pre><code>$curldata = iconv($encoding, "UTF-8", $curldata);
  
  // save to file to test output
  file_put_contents('test.html', $curldata);
  </code></pre>
  
  <p>Not sure if this is the best way to go about this, but my <code>test.html</code> output no longer has any encoding for special characters, so... (perhaps) mission accomplished.</p>
  
  <p>As I parse through the data, I then notice this character.</p>
  
  <blockquote>
    <p>，</p>
  </blockquote>
  
  <p>Not an ordinary comma... [Comparison: ,/，]</p>
  
  <p>But acts like one. Try doing a <code>ctrl+f</code> and try to find a comma. It treats them as the same, and both as a UTF-8 character - <code>var_dump(mb_detect_encoding('，'));</code></p>
  
  <p>I look at my table row, and see it as a row inserted as such</p>
  
  <blockquote>
    <p>8，8</p>
  </blockquote>
  
  <p>If I try to search for a <code>,</code> it does indeed bring back the instances where <code>，</code>is present.</p>
  
  <p>Vice versa, if I search for <code>，</code> it brings back all instances where that and a comma occurs.</p>
  
  <p>Basically for all intents and purposes it is a comma, yet obviously isn't.</p>
  
  <p>This is of course workable, but rather annoying and feels riddled with inconsistency.</p>
  
  <p>Can anyone explain why the two commas are the same, yet obviously different? </p>
  
  <p>Is there a solution for me to prevent these odd characters from entering my CURL response, or further in within my <code>DOM</code> response and <code>PDO</code> Insert.</p>
  
  <p>edit:</p>
  
  <p>If relevant,</p>
  
  <pre><code>// dom
  $dom = new DOMDocument('1.0', 'utf-8');
  libxml_use_internal_errors(true);
  $dom-&gt;preserveWhiteSpace = FALSE;
  $dom-&gt;loadHTML(mb_convert_encoding($curldata, 'HTML-ENTITIES', 'UTF-8'));
  
  // pdo
  $pdoquery = "INSERT INTO `table` (`Attr`) VALUES (?)";
  $value = "8，8";
  $stmt = $pdo-&gt;prepare("INSERT INTO `table` (`Attr`) VALUES (?)");
  $stmt-&gt;execute([$value]);
  </code></pre>
  
  <p>edit 2:</p>
  
  <p>Well, it appears to be a <code>FULLWIDTH COMMA</code>..</p>
  
  <pre><code>var_dump(utf8_to_unicode('，'));
  </code></pre>
  
  <blockquote>
    <p>string '%uff0c' (length=6)</p>
  </blockquote>
  
  <pre><code>var_dump(utf8_to_unicode(','));
  </code></pre>
  
  <blockquote>
    <p>string '%2c' (length=3)</p>
  </blockquote>
  
  <p>Starting to make more sense... now to figure out how to prevent such characters from entering the curl response/DOM/database...</p>