title: Easier way to dynamically create Javascript using PHP
body: <p>I'm currently using PHP to dynamically create a javascript which will be <code>echoed</code> on the page. </p>
  
  <p><strong>Sample Code:</strong></p>
  
  <pre><code>$JS .= '&lt;script&gt;';
  
  if($condition == true) {
      $JS .= 'alert("Yo its true omg!");
  }
  
  $JS .= "&lt;/script&gt;";
  </code></pre>
  
  <p>As you can see, this will eventually get messy with ll the <code>'</code> quotes and escaping of single quotes within the double quotes...</p>
  
  <p>Is there a better way to do this?</p>