List Info

Thread: URLify regex (PHP)




URLify regex (PHP)
user name
2006-03-29 03:14:03
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 regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

URLify regex (PHP)
user name
2006-03-30 15:34:15
There is a Perl sample in the second chapter of Mastering
Regular
Expressions, Second Edition by Jeffrey Friedl if that helps
at all.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )