title: How to get single quotes inside a javascript variable (=function parameter) escaped?
body: <p>I'm writing javascript with php like:</p>
  
  <pre><code>echo '&lt;a class="'.$classTag.'" href="javascript: OpenModalDialog(\''.$MenuItem['table_name'].'\', \''.($MenuItem['where_clause']).'\');"&gt;&lt;span&gt;View Data&lt;/span&gt;&lt;/a&gt;';
  </code></pre>
  
  <p>This results in this:</p>
  
  <pre><code>echo '&lt;a class="'.$classTag.'" href="javascript: OpenModalDialog('input_lijstwerk_401', ' WHERE DATE_FORMAT(Datum, '%Y%m') = '201606'');"&gt;&lt;span&gt;View Data&lt;/span&gt;&lt;/a&gt;';
  </code></pre>
  
  <p>The problem is in the variable: $MenuItem['where_clause'] with the single quotes inside the signature of the openModalDialog:
  ' WHERE DATE_FORMAT(Datum, '%Y%m') = '201606''</p>
  
  <p>I have tried with json_encode, htmlspecialchars. We are working with PHP7</p>
  
  <p>I hope that someone can help me out this problem.</p>
  
  <p>Thanks,</p>
  
  <p>Nico</p>