![]() |
[PHP/Perl?] eregs??
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs))
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $text); i can see a lot of [{( +:/^ and stuff.... what are they there for?(i know the basic function of ereg_replace) (yes...i took this from the php manual which hasnt explained any of this) |
well, I'm gonna assume this is a regular expression of some sort... in general [] surround a list so [0-9] is the list of the digits 0 though 9... ()'s are just precidence markers ^ before a list means everything BUT those things some of those are just literal characters. so [0-9]-[0-3] may mean a digit from 0 to 9, a dash, and a digit from 0 to 3. hope that helps a bit... I don't do a whole lot of regular expressions...
|
Right, [0-9] means match any of the characters 0123456789. The {4} means match any of the preceding characters four times, and {1,2} means match them at least one but not more than two times. The parentheses mean to put whatever is inside them into the variables $regs[1], $regs[2], $regs[3], etc., and I think the entire matching string is put in $regs[0]. The dashes just match dashes. So the first regular expression would match 1998-4-10 (and "1998-4-10" would be put in $regs[0], "1998" in $regs[1], "4" in $regs[2], and "10" in $regs[3]) but not 10-22-1 or a333-aa-9b.
The whole of the second part looks like it goes through looking for plain text URLs and replaces them with HTML links. [[:alpha:]]+:// means match any alphabetic characters at least one time followed by a ://, so for example it would match http:// or ftp://. [^<>[:space:]]+[[:alnum:]/] matches anything except <> or whitespace characters at least one time followed by a / or alphanumeric character at the end of the string. \0 means the entire matched string in the context of that function. Note there are two types of regular expressions in PHP, Perl-compatible regular expressions with the preg functions, and POSIX extended expressions with the ereg functions. They are similar but there are some minor differences that I don't really know. |
sweet, thx I wasn't sure on the {}'s nonsensical :)
|
the php manual with notes has a list of the identifiers you can use with regular expressions
I think someone said its not 100% right, but its good enough to figure out what they all do |
All times are GMT -8. The time now is 12:20 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project