title: Replace characters in MySQL query result PHP
body: <p>Couldn't find an exact answer to this question on here, though it may be simple (if there is an answer please point me in the right direction).</p>
  
  <p>I am pulling some data from MySQL and some of the characters are causing the data not to be displayed at the end point.  I therefore need to single out these specific characters and replace them with a permitted character.  Specifically I need to change &amp; , ' and + .  I have to do this working from this query:</p>
  
  <pre><code>$query = "select * from data where a_data_id=".$ID." AND a_discard_data_from!=1";
  </code></pre>
  
  <p>I was wondering if I can add to this string, or after this string, some rule to replace instances &amp; , ' or + with another character/s.</p>
  
  <p>Thanks for looking!</p>
  
  <p>NOTE:  There is no problem with the string above, it is functioning fine, I just want to add to it or after it some type of code that will replace certain characters in the data pulled from the query</p>
  
  <p>Surrounding Code:</p>
  
  <pre><code>$arr="";
  $main_arr="";
  $query = "select * from data where a_data_id=".$ID." AND a_discard_data_from!=1";
  $query .=" and last_update &gt;= " . '"' . $dataDate . '"';
  $table = mysql_query($query);
  if (mysql_num_rows($table) &gt; 0) {
      while ($row = mysql_fetch_assoc($table)) {
          foreach ($row as $key =&gt; $value) {
              $arr[$key] = $value;
              if ($key == "to_data_id") {    
                 $array=mysql_fetch_array(mysql_query("select name,additional from details where data_id=".$value));
                  $arr["data_id"] = $array['additional'].".".$array['name'];
              }
          }
          $main_arr[] = $arr;
      }
  }
  
  
  
  $data = json_encode($main_arr);
  </code></pre>
  
  <p>Just how to slow it into this code would be great, thank you!  (This code works fine, just want to know what I could change / add to replace those characters).</p>
  
  <p>UPDATE:  Is anyone able to give me an answer with how I might be able to use strtr()function to replace the results please?  Thanks again for the responses!</p>