A pal asked me to come up with a regex that will wrap URLs
in an anchor
tag while in a string:
Here's what I came up with:
<?php
$string = "www.GOOGLE.com/~dude/index.html#fred
this is a test
(www.mang.net/test.php:443?php.totally.roxorz=1&%20+%20)
line
with http://yahoo.net and
maybe one of these http://www.fark.com, note
the comma at the end of www.example.com.";
$any = "/#~:.?+=&% !\-.:?";
$regex =
"((http://(www\.)?|www\.)[A-Za-z0-9\.\/\?\=\%\
+\:\&\#\~]+)";
print "$string\n\n";
print preg_replace("#$regex#i", "<a
href='$1'>$1</a>", $string);
?>
I'd love to see other ways to do this. I am an old Perl
guy so I know
Tim Towtdi.
-Ken
http://lastinglinks.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|