|
-
Jan 22nd, 2004, 04:32 AM
#1
Thread Starter
Lively Member
regular expression of links.
hello,
I am building a system that allows users to enter text.
something like a guestbook.
I would like to do that if the user write a link that starts with www in the text it will turn the link into a clickable link that means it will add the <a href=""></a> tag to it.
is there any regular expression that can help me with such thing?
thanks in advanced for any help.
Yair
-
Jan 22nd, 2004, 06:23 AM
#2
This expression should do the same as the link finder of vBulletin.
"(www\.[^\w]+)|(http://[^\w]+)"
You need to add the http:// if it isn't already there, else the link is interpreted as relative.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 22nd, 2004, 08:05 AM
#3
Thread Starter
Lively Member
thank you
I will now try to find a place which will help me to understand this regular expression.
thanks again
Yair
-
Jan 22nd, 2004, 10:39 AM
#4
Err... ask me? 
The expression matches one of two patterns. The first pattern is
(www\.[^\w]+)
Which means "www." followed by 1 or more non-whitespace characters. Captured.
The second pattern is
(http://[^\w]+)
Which mean "http://" followed by 1 or more non-whitespace characters. Captured.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 22nd, 2004, 11:48 AM
#5
Thread Starter
Lively Member
thanks
I didnt wanted to bother you with lazyness questions ...

thank you
Yair
-
Jan 22nd, 2004, 01:12 PM
#6
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 22nd, 2004, 07:52 PM
#7
Stuck in the 80s
CornedBee, I got an error (Unknown modifier '|') when I tried that.
I've always used:
Code:
$text = preg_replace('/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i', '<a href="\\0">\\0</a>', $text);
-
Jan 23rd, 2004, 06:16 AM
#8
'tis weird, | is one of the most basic features of regular expressions.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 23rd, 2004, 12:55 PM
#9
Stuck in the 80s
Originally posted by CornedBee
'tis weird, | is one of the most basic features of regular expressions.
Does the expression work for you?
I tried changing it to:
Code:
"((www\.[^\w]+)|(http://[^\w]+))"
Thinking that might help. It gets rid of the error, but doesn't do anything to the text.
-
Jan 23rd, 2004, 01:03 PM
#10
Haven't tried. I just think it's weird that I get such a simple expression wrong
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|