Forum Moderators: coopster
The statements is
PHP Code:
if (eregi("[-rwx]+ +[0-9]+ [0-9a-zA-Z]+ +([0-9\.kMG]+) [a-zA-Z]+ ([a-zA-Z]+ [0-9]+) ([0-9:]+) ([0-9]+) ((.+)\.(doc¦pdf¦xls¦vsd¦tif¦mpp¦ppt¦jpg¦mdb¦jpeg¦bmp))", $line, $eregs))
The value of $ line is
-rw-r--r-- 1 root 2.3M Wed Nov 02 07:24:12 2005 5S.mdb The value of $eregs is
array(8) { [0]=> string(65) "-rw-r--r-- 1 root 2.3M Wed Nov 02 07:24:12 2005 5S.mdb" [1]=> string(4) "2.3M" [2]=> string(6) "Nov 02" [3]=> string(8) "07:24:12" [4]=> string(4) "2005" [5]=> string(6) "5S.mdb" [6]=> string(2) "5S" [7]=> string(3) "mdb" }
I really don't know quite how to decipher this eregi statement and he who wrote it has moved on to another job. It is returning a true condition, so it is finding some part of the search string in the $line variable. I just don't know what so that I can take it out.
Any help is greatly appreciated.
D
The first thing to note is that $eregs is an array which will be populated with the parenthesised substrings which matched the pattern, if a match occurred. See the PHP manual -- www.php.net/ereg -- for further details.
So it may help to echo eregs -- especially eregs[0], which will contain a copy of the string matched. (But bear in mind that if no matches are found, $eregs will not be altered by eregi().)
Also note that eregi ignores case when matching. (So ([0-9\.kMG]+) will match one or more consecutive (digit or period (the backslash escapes the '.') or upper or lower case k, m, or g.) Eg. it will match '123..9kK')
If that doesn't help, come back here!
<added>Sorry -- I see you have provided the value of eregs! So eregs[0] contains the match.</added>
Take a look at the regular expression and the resulting array.
The string to consider:
[0]=> string(65) "-rw-r--r-- 1 root 2.3M Wed Nov 02 07:24:12 2005 5S.mdb"
The first match:
regexp: ([0-9\.kMG]+)
match: [1]=> string(4) "2.3M"
The second match:
regexp: ([a-zA-Z]+ [0-9]+)
match: [1]=> string(6) "Nov 02"
The third match:
regexp: ([0-9:]+)
match: [1]=> string(8) "07:24:12"
The fourth match:
regexp: ([0-9]+)
match: [1]=> string(4) "2005"
The fifth match:
regexp: ((.+)\.(doc¦pdf¦xls¦vsd¦tif¦mpp¦ppt¦jpg¦mdb¦jpeg¦bmp))
match: [1]=> string(6) "5S.mdb"
The sixth match:
regexp: ((.+)\.(doc¦pdf¦xls¦vsd¦tif¦mpp¦ppt¦jpg¦mdb¦jpeg¦bmp))
match: [1]=> string(2) "5S"
The seventh match:
regexp: ((.+)\.(doc¦pdf¦xls¦vsd¦tif¦mpp¦ppt¦jpg¦mdb¦jpeg¦bmp))
match: [1]=> string(3) "mdb"
Hope that helps!