note 14317 added to function.eregi-replace.php
| From: | piotr at kiragadesign dot art dot pl | Date: | Thu, 26 Jul 2001 13:49:14 +0000 |
| Subject: | note 14317 added to function.eregi-replace.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-15870@lists.php.net to get a copy of this message | ||
Hi,
The idea:
eregi_replace( "((http|https|mailto|ftp):(\/\/)?[^[:space:]<>]{1,})", "<a
href='\\1'>\\1</a>",$url)
is very smart, and short, but i've found one bug. It has errors while interpreting URLs in
normal texts, because it includes in <a></a> chars placed right after parsed URL, for
example:
"This is our link: http://www.something.xx/didi.php. So please click
it!"
The result:
This is our link: <a href='http://www.something.xx/didi.php.'>http://www.something.xx/didi.php.</a>
So please click it!
##### HINT #####
In my experience, the best bugless idea is to use:
eregi_replace("((ftp://)|(http://)|(www))(([a-z0-9.\-])*)(@)?(([a-z0-9\.])*)(([:/])?)((([a-z0-9]*)(@?)/*)+([.a-z]{2,4}){1})?((\??[a-z0-9\=]*)?)((\&[a-z0-9\=]*)?)(([\.a-z]){2,4})?",
"<a href=\"\\0\">\\0</a>", $out);
This second idea was posted here by someone else. And is placed above my note. Read it. It's
very valuable (for me was). ;)
Have a nice code. ;)
http://www.php.net/manual/it/function.eregi-replace.php