Automatically create HTML-links for urls

There’s a little php code snippet as example for replacing pure text-url into a clickable HTML-link. The presentation of this php snippet is just used as a test of the code highlighting I want to use on this page.

<?php
   function AutoVerlinkung ($msg) {
     // http
     $msg = str_replace("http://www.","www.",$msg);
     $msg = str_replace("www.","http://www.",$msg);
     $msg = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<A TARGET=\"_blank\" HREF=\"$1\">$1</A>", $msg);

     // mail
      $msg = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A HREF=\"mailto:$1\">$1</A>",$msg);
      return $msg;
   }

   $demo = "www.meineurl.de oder http://www.meineurl.de oder meine@email.de";
  $demoVerlinkt = AutoVerlinkung($demo);
  echo "<p>aus: <b>".$demo."</b></p>";
  echo "<p>wird: <b>".$demoVerlinkt."</b></p>";
?> 

The seen snippet belongs to a unknown, brilliant developer. I hope not to hurt any rights by showing this bit of code.

Many thanks in advance for your appreciation!

  • http://www.newby2000.de newby2000

    I recommend you to be aware of the point of view shipped by using automatic linking to email addresses on your website. Especially in cases of sharing authoring with others or just inclusing the above into commenting system on your site, you should give the others possibilty to prevent their addresses from beeing catched by crawlers due to spamming abuse!

  • http://www.newby2000.de newby2000

    They say if you play a Microsoft Windows CD backwards it will play satanic messages. But thats nothing, if you play it forwards it installs Windows.