phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Web Content: Changing URL Text become Active URL

Tag: web content, url, text   Category: PHP Basic
post: 26 Apr 2008 read: 125


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.

<?php

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.




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting