Forum Moderators: phranque
I have been facing problems in making text urls, e.g (www.example.com), a click-able URL on the fly. The problem is that i have text urls as well s proper html urls in my html. when i try to convert text urls to html links, the already proper html links are disturbed too and vice versa.
I have tried the following kind of patterns,
// $text = eregi_replace('[^<]([[:space:]()[{}])?(((f¦ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)([[:space:]()[{}])', ' <a href="\\3" target=\"_blank\">\\3</a> ', $text);
//$text = eregi_replace('[^<a]([[:space:]()[{}])?(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)([[:space:]()[{}])?', '\\1 <a href="http://\\2" target=\"_blank\">\\2</a> ', $text);
//$text = eregi_replace('([[:space:]()[{}])?(file:(/)?[-a-zA-Z0-9@:%_\+.~#?&//=]+)([[:space:]()[{}])?', '\\1 <a href="\\2">\\2</a> ', $text);
//$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\2</a>', $text);
//$text = eregi_replace('(((f¦ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a href="\\1" target=_blank>\\1</a>', $text);
//$text=preg_replace( "/[^(<a href)]((http¦ftp)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\">\\0</a>", $text );
//$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1<a href="http://\\2" target=_blank>\\2</a>', $text);
//$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);
$text = preg_replace('\b(https?¦ftp¦file):\/\/[-A-Z0-9+&@#\/%?=~_¦!:,.;]*[-A-Z0-9+&@#\/%=~_¦]', '<a href="\\0">\\0<\/a>', $text);
return $text;
none of them is working for me.
Can anybody help please how to accomplish this?
thank you very much
-------------------------------
www.example.com lots of html crap and other things then <a href="http://example.com/somepage.html">link</a> again other text and similar urls
------------------------------------------------------
then the text urls are converted to clickable links but html urls are broken like
href="http://example.com/somepage.html">link</a>
the starting <a is disappeared.
i am using the same preg_replace as i posted in the other thread with negative assertion.
any help is much appreciated. you can test your regex with both types of links in single string to see the affect.
www.example.comlinks within the text. We should keep our responses in one thread or the other though, so we don't create confusion amongst ourselves or future readers.
anyway, I will keep future posts on this problem here in apache as it is more of regex question than php.
my goal is very simple,
1 - if a url is present in the text form then make it clickable e.g
www.example.com example.com http://example.com/page.ext http://www.example.com/directories/pages/
2 - if proper html links are present then do not touch it at all e.g all above links with <a href=''></a> tags.
I have tried uncounted regexs but am not able to solve this. If it works for text url then breaks html urls and if does not break html then text urls are not converted.