title: User inputted string, when containing certain special characters, does not match database string though they appear to be equivalent strings
body: <p>I have searched for similar questions and have found <a href="https://stackoverflow.com/questions/4961206/strings-appear-exact-but-they-do-not-match">this</a>
  but it has not helped for my situation. On my site, a user inputs an answer. The string is sent via an ajax call to a php file. The string may or may not contain special characters, so I use </p>
  
  <pre><code>encodeURIComponent()
  </code></pre>
  
  <p>before the string is sent to the php file.</p>
  
  <p>The user-inputted string is compared in the php file with a string that represents the "correct answer", and if the strings are found to be equivalent strings after processing, the user-inputted answer is "correct". I have not had a problem with any strings lately until today. Until today, strings with letters, special characters (parentheses, minus sign, plus sign) and numbers have worked fine using the following processing in php:</p>
  
  <pre><code>&lt;?php include 'connect.php';
  
  $UserInput = trim($_GET['userinput']);
  $QID = mysqli_real_escape_string($cxn, $_GET['qid']);
  $sqlIQ = mysqli_fetch_assoc(mysqli_query($cxn, "SELECT answer FROM IndexQuestions WHERE sampqid = $QID"));
  
  
  $StrReplaceArray = array("&lt;i&gt;", "&lt;/i&gt;", "&lt;/sup&gt;", " ");
  $CorrectAnswer1 = str_replace($StrReplaceArray, "", $sqlIQ['answer']);
  $CorrectAnswer2 = str_replace("&lt;sup&gt;", "^", $CorrectAnswer1);
  
  $UserAnswer1 = str_replace(" ", "", $UserInput);
  $UserAnswer2 = str_replace("+-", "-", $UserAnswer1);
  
  if (strcasecmp($UserAnswer2, $CorrectAnswer2) == 0) {
      $CorrectOrNot = 'Correct';
  } else {
      $CorrectOrNot = 'Incorrect';
  }
  </code></pre>
  
  <p>However, the latest string is not working. The user-inputted string is <strong>-2 ± √3</strong> which is sent to the php file as <strong><code>-2 &amp;plusmn; &amp;radic;3</code></strong> (with or without the whitespace). The "correct answer" saved in another table is <strong><code>-2 &amp;plusmn; &amp;radic;3</code></strong>. I have echoed the following:</p>
  
  <pre><code>echo $UserAnswer2 . " " . $CorrectAnswer2; //after str_replace processing shown above
  </code></pre>
  
  <p>and the html output for each variable looks identical to me. I have also tried the following for comparative purposes (instead of <code>strcasecmp</code>):</p>
  
  <pre><code>if ($UserAnswer2 == htmlentities($CorrectAnswer2)) { //etc.
  </code></pre>
  
  <p>but still the same. </p>
  
  <p>When I check a separate table (which stores the user's answer), the answer is stored the way I want it to be:</p>
  
  <pre><code>$unixtime = time();
  $AnswerID = substr(md5(rand(0, 1000000)), 0, 10).$unixtime;
  
  $sqlIQStats = mysqli_query($cxn, "INSERT INTO IQStats (answer_id, useranswer) VALUES ('$AnswerID', '".htmlentities($UserAnswer2)."')");
  </code></pre>
  
  <p>and appears in the database as <strong><code>-2 &amp;plusmn; &amp;radic;3</code></strong>.</p>
  
  <p>The html charset the site uses is <code>charset=utf-8</code>. </p>
  
  <p>var_dump gives the following (with no spaces for user answer): $UserInput and $UserAnswer2 both give string(8) "-2±√3" whereas $CorrectAnswer2 gives string(18) "-2±√3"</p>
  
  <p>Does anyone have any ideas as to why the strings, after string-processing and comparison in the php file, are found to be inequivalent strings?</p>