Forum Moderators: coopster

Message Too Old, No Replies

Clickable URL

         

jojy

2:42 pm on Feb 20, 2009 (gmt 0)

10+ Year Member



Hello,
I am stuck with clickable url regular expression. I allow users to put <a href tag and they also put urls only. What I am doing is to covert urls into click able but this mess with <a href. Here is my code


function make_clickable_urls($text) {
$text = eregi_replace('(((f¦ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target="_blank">\\1</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" target="_blank">\\1</a>', $text);
return $text;
}
echo make_clickable_urls('<a href="http://site.com">Site 1</a>, http://www.webmasterworld.com');

Any help?

Thanks

jojy

9:32 pm on Feb 20, 2009 (gmt 0)

10+ Year Member



anyone can help with me with this [webmasterworld.com...]

$text=preg_replace( "/(?<!<a href=\")((http¦ftp)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\">\\0</a>", $text );

I can't get it working

jojy

12:12 am on Feb 23, 2009 (gmt 0)

10+ Year Member



coopster can you tell me whats wrong with this $pattern = "/(?<!=\")((http¦ftp)s?:\/\/[^<>\s]+)/i";

you suggested this to phparion on above thread url

coopster

7:15 pm on Feb 23, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Did you remember to retype the broken pipe symbol? The forum software breaks the pipe symbol so you need to replace the broken pipe symbol with the pipe symbol.

jojy

10:09 pm on Feb 23, 2009 (gmt 0)

10+ Year Member



oh dear coopster.. this really made me sick.. thank you so much for your help :)

jojy

9:46 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



this rule failed with <a href="http://url.com">http://url.com</a> I wish if I could be a regex expert :(

coopster

11:38 pm on Feb 24, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Put the "a href" part back in, as mentioned in the other thread.

jojy

12:56 am on Feb 25, 2009 (gmt 0)

10+ Year Member



thanks for the reply. I tried to put <a href at all places.. but it doesn't work for me.

$text = preg_replace("/(?<!<a href=\")(?<!=\")((http¦ftp)s?:\/\/[^<>\s]+)/i", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $text );

Sorry I am not good at making RE, please correct above line.