Auto-link function for PHP.
Posted: Sat Nov 14, 2009 4:51 pm
I am at the end of my wits. I have scoured Google and all I can find are functions that simply do not work for me.
I'm making a cute, little, forum system. I want the words to auto-link. That means I put the string through my "message convert" function, which also converts the [ b ] stuff to < b >, but none of these work!
That's the best one I have, and it doesn't even turn the http://www.'s into links, and it breaks long links. I have put over an hour into google, I even searched these boards. Nothing.
I'm hoping one of you have the end-all function that will just convert http:// and www. properly.
I'm making a cute, little, forum system. I want the words to auto-link. That means I put the string through my "message convert" function, which also converts the [ b ] stuff to < b >, but none of these work!
Code: Select all
function makeURL($URL) {
$URL = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:\+.~#?&//=]+)','<a href=\\1>\\1</a>', $URL);
$URL = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:\+.~#?&//=]+)','<a href=\\1>\\1</a>', $URL);
$URL = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href=\\1>\\1</a>', $URL);
return $URL;
}
I'm hoping one of you have the end-all function that will just convert http:// and www. properly.