title: How to escape text coming from PHP in JavaScript?
body: <p>I am using jPlayer to display some videos and I create the playlist on the fly in a php foreach statement:</p>
  
  <pre><code>var playlistacting = 
              [
          &lt;?php foreach($this-&gt;result as $val){?&gt;
                  {
                      title:  '&lt;?php echo $val-&gt;getTitle();?&gt;',
                      artist: '&lt;?php echo $val-&gt;getDes();?&gt;',
                      poster: "&lt;?php echo $val-&gt;getVideoId();?&gt;.jpg",
                      thumb:  "&lt;?php echo $val-&gt;getVideoId();?&gt;.jpg",
                      flv:    "&lt;?php echo $val-&gt;getVideoId();?&gt;.flv",
                  },
          &lt;?php }?&gt;
  ];
  </code></pre>
  
  <p>and <code>$val-&gt;getDes()</code> example would be <code>I have a one-hour (approximately) solo musical revue called "Manhattan With A Twist". The entire...</code></p>
  
  <p>the error I get is</p>
  
  <pre><code>unterminated string literal
  [Break On This Error]   
  
  artist: 'I have a one-hour (approximately)solo musical revue called "Manhattan W...
  
  jquery.js (line 2, col 32)
  </code></pre>
  
  <p>and is poining to the <code>'</code> at the beginning of the string.</p>
  
  <p>I can do this: <code>title:  "&lt;?php echo htmlspecialchars($val-&gt;getTitle());?&gt;",</code></p>
  
  <p>and I will get the same error but with <code>"</code> instead of <code>'</code>.</p>
  
  <p>I'm not sure what is happening here. Is it complaining about that <code>'</code> not being escaped or what?</p>
  
  <p>Any ideas?</p>