title: Parameter encoding (quotes and space character)
body: <p>So I'm sending a string parameter to javascript function, and the problem is space characters and/or quotes. I can have either one working, but can't figure out how to get both ways to work at the same time.</p>
  <p>I left encodeURIComponent and decodeURIComponent to my example as I currently use them to deal with spaces.</p>
  <p>Javascript:</p>
  <pre><code>function alertTitle(title){
      alert(decodeURIComponent(title));
  }
  </code></pre>
  <p>PHP:</p>
  <pre><code>//...fetching from MySQL
  $title = $row['title'];
  
  //If $title content is wrapped in single or double quotes, this will do:
  $title = str_replace(&quot;\&quot;&quot;,&quot;&amp;quot;&quot;,$row['title']);
  //But if it's not, and has spaces, I have to wrap it in quotes for encodeURIComponent:
  $title = '\''.$row['title'].'\''; 
  //And that obviously gives error in encodeURIComponent if $title happens already to have
  // single quotes
  
  //..And sending $title to javascript:
  echo '&lt;a onclick=&quot;alertTitle(encodeURIComponent('.$title.'));&quot; href=&quot;#&quot;&gt;Alert&lt;/a&gt;';
  </code></pre>
  <p>So somehow I need to escape single quotes also, or then come up with some very different approach.
  But this is already so close, so I wish I have just missed something simple.</p>
  <p>$title might be anykind of the following examples:</p>
  <blockquote>
  <p>&quot;Title&quot;</p>
  <p>&quot;Title with spaces&quot;</p>
  <p>'Title'</p>
  <p>'Title' with &quot;all combined&quot;</p>
  <p>Title &quot;Blaablaa&quot; here</p>
  </blockquote>
  <p>And so on.</p>
  <p>All hints are more than welcome. Thanks!</p>