title: Escape a string full of " and ' in PHP
body: <p>I need to escape a string that has a lot of " and '. The string is a binary from a database. I have this:</p>
  
  <pre><code>$String64 = '&lt;a data-String64="'.$binary64.'"&gt;Link&lt;/a&gt;';
  </code></pre>
  
  <p>So the <code>$binary64</code> has some text like <code>target:"29", width=100'height=200...</code>  </p>
  
  <p>So my problem is that the <code>"'</code> are closing the <code>data-String64</code> before it can output the entire variable. I have tried addslashs(), but nothing good. </p>
  
  <p>How can I escape this?</p>
  
  <p>This is what I have tried:</p>
  
  <pre><code>$String64 = "&lt;a data-string64='${binary64}'&gt;&lt;b&gt;&lt;i class='fa fa-eye'&gt;&lt;/i&gt;&lt;/b&gt;&lt;/a&gt;";
  $String64 = "&lt;a data-string64='{$binary64}'&gt;&lt;b&gt;&lt;i class='fa fa-eye'&gt;&lt;/i&gt;&lt;/b&gt;&lt;/a&gt;";
  $String64 = "&lt;a data-string64=\'${binary64}\'&gt;&lt;b&gt;&lt;i class='fa fa-eye'&gt;&lt;/i&gt;&lt;/b&gt;&lt;/a&gt;";
  $String64 = "&lt;a data-string64=\'$binary64\'&gt;&lt;b&gt;&lt;i class='fa fa-eye'&gt;&lt;/i&gt;&lt;/b&gt;&lt;/a&gt;";
  $String64 = "&lt;a data-string64=\"$binary64\"&gt;&lt;b&gt;&lt;i class=\"fa fa-eye\"&gt;&lt;/i&gt;&lt;/b&gt;&lt;/a&gt;";
  </code></pre>