From:             [EMAIL PROTECTED]
Operating system: Linux 2.4.17 (self compiled)
PHP version:      4.1.2
PHP Bug Type:     Feature/Change Request
Bug description:  replace url with a link

I could not find any function to replace an url within a string with a
link

if someone writes http://www.php.net, I want I to be replaced with <a
href="http://www.php.net>

I saw this on your page too, its easy to recreate your function myself
with 

$string =
preg_replace("((http://)([a-zA-Z1-9\-_\.]+\.[a-zA-Z1-9\-_]+\.[a-z]{2,3}(/[a-z\-/\._\?=&]+)?))",
"<a href=\"\\1\\2\" target=\"_blank\">\\0</a>", $string);

but wouldnt it be nice to replace an url like www.php.net too?

For now, I use

$string =
preg_replace("((http://|ftp://)?([a-zA-Z1-9\-_\.]+\.[a-zA-Z1-9\-_]+\.[a-z]{2,3}(/[a-z\-/\._\?=&]+)?))",
"<a href=\"\\1\\2\" target=\"_blank\">\\0</a>", $string);

to convert every url to an link.
but if you have an url like www.php.net, it will create a link like <a
href="www.php.net">, wich will not work.
To prevent this, I use

$string =
preg_replace("((href=\")([a-zA-Z1-9\-_\.]+\.[a-zA-Z1-9\-_]+\.[a-z]{2,3}(/[a-z\-/\._\?=&]+)?))",
"href=\"http://\\2";, $string);

wich will replace anything like href="something.php.net with
href="http://something.php.net

I think it will be nice for other people to include (something like) this
function in php, because many people would use it

thanks
-- 
Edit bug report at http://bugs.php.net/?id=16642&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=16642&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=16642&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=16642&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=16642&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=16642&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=16642&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=16642&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=16642&r=submittedtwice

Reply via email to