title: jQuery & PHP: Encode & Decode URL
body: <p>I am passing a string through a URL to another page whenever a link is clicked.</p>
  
  <p><strong>The original <code>a</code> tag and its <code>href</code> are created via a PHP while loop as follows:</strong></p>
  
  <pre><code>&lt;a href=".($row['secondary'] == 'true' ? "secondary_imgs.php?imgId=".$row['imgId']."
      &amp;imgTitle=".$row['imgTitle']."" : "new_arrivals_img/".$row['imgURL']."")."&gt;
  </code></pre>
  
  <p><strong>Note:</strong> The <code>a</code> tag <em>does</em> contain other attributes but I removed them for simplicity.</p>
  
  <p><strong>The <code>href</code> is then appended, with the current window dimensions, using the following jQuery function:</strong></p>
  
  <pre><code>$("a[href^='secondary_imgs.php']").click(function(){
      var pageWidth = $(window).width();
      var pageHeight = $(window).height();
      var url = $(this).attr('href');
      var idx = url.indexOf('&amp;pageWidth=');
      if (idx != -1) {
          url = url.substr(0, idx);
      }
      url += '&amp;pageWidth=' + pageWidth + '&amp;pageHeight=' + pageHeight;
      $(this).attr('href', url);
  });
  </code></pre>
  
  <p>My question is, what method(s) of encoding the URL should I use in this case, seeing as it will need to be done with first PHP, then jQuery/JavaScript, and finally decoded via PHP? 
  Or <em>will</em> it need to be done in both PHP and jQuery/JavaScript? The original PHP <code>$row['imgTitle']</code> will <em>always</em> have at least spaces in it, and so I know it needs to be done then for sure. But seeing as the appended values will always be a variable equalling a number, does that need to be encoded as well?</p>
  
  <p>I know there are several methods of encoding/decoding URLs in each coding language, and my knowledge isn't adequate enough to make the choice.</p>
  
  <p>If someone could also provide an example of how I would perform each step, it would be much appreciated.</p>