title: Escaping URLs in an html attribute in PHP
body: <p>I am currently working with some existing code that takes a URL out of the request and inputs it into the source of an anchor. This is clearly an opening for XSS and using urlencoding doesn't retain the sanity of the url inside the anchor. I'm curious what the safest way to escape the data without breaking the link would be.</p>
  
  <p>i.e.</p>
  
  <pre><code> &lt;? 
      $url = $_REQUEST['url'];
      echo '&lt;a href="' . $url . '"&gt;sometext&lt;/a&gt;'; 
  ?&gt;
  </code></pre>