title: Writing HTML with JavaScript using PHP
body: <p>So I've got this PHP that's writing some JavaScript that looks something like this:</p>
  
  <pre><code>echo '&lt;script type="text/javascript"&gt;
  
  var videoArr=["'.implode('", "', $videos).'"];
  var titleArr=["'.implode('", "', $titles).'"];
  var explanationArr=["'.implode('", "', $explanations).'"];
  var i = 0;
  
  function appendVideo(i) {
  
  var url ="http://www.youtube.com/embed/" + videoArr[i] + "?rel=0&amp;amp;autohide=1&amp;amp;showinfo=0";
  
  $("#stage").append("&lt;div class=\"video\"&gt;");
  $("#stage").append(titleArr[i] + "&lt;br /&gt;");
  $("#stage").append("&lt;iframe width=\"400\" height=\"225\" src=\"" + url + "\" frameborder=\"0\" allowfullscreen&gt;&lt;/iframe&gt;");
  $("#stage").append("&lt;br /&gt;&lt;img src=\"images/btn_play.png\" onclick=\"play(\'" + videoArr[i] + "\')\" /&gt;");
  $("#stage").append("&lt;img src=\"images/btn_show.png\" onclick=\"show(\'" + videoArr[i] + "\')\" /&gt;&lt;br /&gt;");
  $("#stage").append("&lt;/div&gt;");
  }
  
  &lt;/script&gt;';
  </code></pre>
  
  <p>But after reading this: <a href="http://littleurl.info/wdl" rel="nofollow">http://littleurl.info/wdl</a> I've learned that I have to do this all in one append for my DIV tags to appear correctly. However I'm finding it impossible to get my syntax correct because I'm doing this all through PHP. Can anyone help me debug the code below? Please remember it's all contained in an echo with single inverted commas.</p>
  
  <pre><code>$("#stage").append("&lt;div class=\"video\"&gt;"+ titleArr[i] + "&lt;br /&gt;
  &lt;iframe width=\"400\" height=\"225\" src=\"" + url + "\" frameborder=\"0\" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;
  &lt;img src=\"images/btn_play.png\" onclick=\"play(\'" + videoArr[i] + "\')\" /&gt;
  &lt;img src=\"images/btn_show.png\" onclick=\"show(\'" + videoArr[i] + "\')\" /&gt;&lt;br /&gt;
  &lt;/div&gt;");
  </code></pre>