php link detection glitch

Jdee

New Member
I use the following function to detect a link in php:\[code\] $pattern_url='~(?>[a-z+]{2,}://|www\.)(?:[a-z0-9]+(?:\.[a-z0-9]+)?@)?(?:(?:[a-z](?:[a-z0-9]|(?<!-)-)*[a-z0-9])(?:\.[a-z](?:[a-z0-9]|(?<!-)-)*[a-z0-9])+|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?:/[^\\/:?*"<>|\n]*[a-z0-9])*/?(?:\?[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?(?:&[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?)*)?(?:#[a-z0-9_%.]+)?~i'; preg_match_all($pattern_url, $imageurl, $matches); for ($i=0; $i < count($matches[0]); $i++) { if(substr($matches[0][$i],0,4)=='www.') $imageurl = str_replace($matches[0][$i],'http://'.$matches[0][$i],$imageurl); } $link = preg_replace($pattern_url,'<div class="postImageDiv"><a target="_blank" href="http://stackoverflow.com/questions/10539586///0"><img src="http://stackoverflow.com/questions/10539586///0" alt="\\0"/></a></div>',$imageurl);\[/code\]It works fine as long as long as there is no .something in between and not at the end. Something like www.google.com/index.php/site.php would stop detected the link after index.php.Also, somehow these links from bloodspot are not identified as links. I wonder why?http://2.bp.blogspot.com/-Mc9x0LRiX.../s1600/creative-and-funny-toilet-signs_21.jpg (ignore content please, it's just an example)How should I improve the function to get better results?Thank you!Dennis
 
Back
Top