Web Content: Changing URL Text become Active URL

Web Content Tips - Part 2: When write article, sometime, we are lazy to write long url like "<a href="www.phpeveryday.com/articles/ Zend-Framework-Session-Locking-and- Unlocking-Namespace-P575.html">Zend framework Session: Locking and Unlocking Namespace</a> We just write only url text without a tag. This post will show you how to activate url text become active url. We use regular expression.

function activateURL($text){
  return eregi_replace("([[:alnum:]]+://[^[:space:]]*[[:alnum:]#?/&= +%_:]]*)","<a href=\"\\1\">\\1</a>",$text);

$test = "This is my url: http://phpeveryday.com/articles/Zend-Framework-Intro-Explaining-Anatomy-of-Zend-Framework-Application-P470.html. It is so lazy to put tag on that url. So, I just use simple activateURL. It work!";

echo activateURL($test);

Hope, it help us.

Bookmark and Share Tag: web content, url, text Category: PHP Basic Post : April 26th 2008 Read: 3,121


blog comments powered by Disqus