Regex...yes i know...please at least look once :)
Posted: Mon Aug 04, 2003 7:08 pm
Well i have a piece of code... and my quesition is more of a please help me to improve it as well as it doesn't work!!
Well it work mostly but i think i have used too much code to do a simple thing...less chat here is the code:
If you haven't noticed the first reg ex is to theoretically replace emails with the equivalent link to an email...well to make it short that doesn;t work...
the second replaces all types of links to the HTML equivalent ant that works fine...
Do you see a flaw in my logic or statement...is there a better way to do this? Also any ideas why my email recognizer sucks??
Thanks!!
Well it work mostly but i think i have used too much code to do a simple thing...less chat here is the code:
Code: Select all
if( eregi( "^[a-z0-9]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,3}$", $EditedMessage ) )
{
$EditedMessage = ereg_replace( "^[a-z0-9]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,3}$", "<a href="mailto:\\0">\\0</a>", $EditedMessage );
}
else
{
$EditedMessage = ereg_replace("(([^\.<>[]]+\.)|([[]]+://))+". "[^\.<>[]]+\.[^<>[]]+", "<a href="http://\\0" target="_blank">\\0</a>", $EditedMessage);
}the second replaces all types of links to the HTML equivalent ant that works fine...
Do you see a flaw in my logic or statement...is there a better way to do this? Also any ideas why my email recognizer sucks??
Thanks!!