Monday, December 1, 2008

function : recognize the url and email in text and replace with url link and mailto

function fnTransformUrl($strText)
{
 
   // convert onkar.tibe@gmail.com into
   //
   $strText = ereg_replace('[-a-z0-9!#$%&\'*+/=?^_`{|}~.]+@([.]?[a-zA-Z0-9_/-])*','\\0',$strText);
   // convert http://www.justmeans.com into
   //
   $strText = ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9?=&%_/-?&%])*)','\\1',$strText);
   // convert http://www.justmeans.com into
   //
   $strText = ereg_replace('(^| )(www([-]*[.]?[a-zA-Z0-9?=&%_/-])*)',' \\2',$strText);
  
   return $strText;
   
}