ftp|http|https Url to hyperlink

Started on the old forum in July 2010 · view the original in the archive · old links redirect here

1 reply · 900 views · started 16 years ago · 1 min read

2 participants
GumSlone Administrator Principal · 1,690 posts #1

Here is a small piece of code which converts url in a string into a hyperlink:

$str = preg_replace("/((ftp)|(http(s?))\:\/\/(([A-z0-9\?\=\-\:\;\.\@\/]+)))/is",'<a href="\\0">\\0</a>',$str); 

example:

$str = 'http://conding-talk.com is the best coding site.';
$str = preg_replace("/((ftp)|(http(s?))\:\/\/(([A-z0-9\?\=\-\:\;\.\@\/]+)))/is",'<a href="\\0">\\0</a>',$str);
echo $str;

and the output will be:

<a href="http://conding-talk.com">http://conding-talk.com</a> is the best coding site.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

OG_35 Junior · 15 posts #2

Thanks for sharing Gum

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close