title: PHP prevent "javascript:" link injection
body: <p>I'm making a website that allows users to store user preferences in a database, including links.</p>
  
  <p>But i've realised that if a user enters <code>javascript: // Malicious code here</code> they can execute any javascript on the page, including the ability to get session ID's.</p>
  
  <p>( The links are shown to other users, thus I want to prevent this from happening )</p>
  
  <p>I've tried the following things to prevent this but they all don't work:</p>
  
  <pre><code>htmlentities()
  htmlspecialchars()
  strip_tags()
  addslashes()
  </code></pre>
  
  <p><strong>Quick example of my code:</strong></p>
  
  <pre><code>$link  = // queried from the database.
  $title = // queried from the database.
  
  echo '&lt;a href="'. $link .'"&gt;'. $title .'&lt;/a&gt;';
  </code></pre>
  
  <p>If you know how I could fix this it would be very much appriciated. </p>