![]() |
![]() |
#1 (permalink) |
Junkie
Location: India
|
[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)
__________________
Why did the Comp. Engineer get X-mas and Halloween mixed up? Because Oct(31) == Dec(25) |
![]() |
![]() |
#2 (permalink) |
Banned
Location: 'bout 2 feet from my iMac
|
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...
|
![]() |
![]() |
#3 (permalink) |
Junkie
Location: San Francisco
|
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. Last edited by n0nsensical; 02-04-2004 at 02:11 PM.. |
![]() |
![]() |
#5 (permalink) |
Tilted
Location: Tha Boro
|
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
__________________
I try to take life one day at a time, but sometimes several days attack me at once. |
![]() |
Tags |
eregs, php or perl |
|
|