This is a discussion on Regex to match ALL characters? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All, I'm trying to parse an Apache httpd.conf file to read the 'Alias' sections using PHP. Take ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi All,
I'm trying to parse an Apache httpd.conf file to read the 'Alias' sections using PHP. Take the one below for example. I have worked out a regex to get the '/icons/' and the path [eregi('^alias (\/[a-z0-9]+/) "([a-z:/ ]+)"',trim($line),$regs)] and that works fine, however what I now want to do is match everything in the <Directory></Directory> section below that. I read that the character '.' matches all characters except for a \n (new line) so I have the httpd.conf file in a string and I've replaced all the \n's with "@NL@" so there's no \n's to trip up the '.' But I've got something wrong because it doesn't work! The value of $alias['/icons/']['path'] is C:/Program Files/Apache Group/Apache/icons/ (checked and confirmed) if (eregi('<Directory "'.$alias['/icons/']['path'].'">(.*)</Directory>',$httpd_conf,$regs)) { echo $regs[1]; } Here's the section from httpd.conf. Alias /icons/ "C:/Program Files/Apache Group/Apache/icons/" <Directory "C:/Program Files/Apache Group/Apache/icons"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> Any ideas? Cheers! -- Bob Brown, IT Consultant, Somewhere in the U.K. http://www.guru.net.nz/ |
|
|||
|
Hi,
I solved it by using preg_match instead and when you're using preg_match you can then use (.*?) which is a non-greedy match. This worked fine. $ereg = '/<Directory "C:\/Program Files\/Apache Group\/Apache\/icons\/">(.*?)<\/Directory>/i'; // Don't forget to escape any forward slashes with backslashes! Cheers! "Bob Brown" <autoreply@guru.net.nz> wrote in message news:eURQa.912$0g3.20278@newsfep1-win.server.ntli.net... > Hi All, > > I'm trying to parse an Apache httpd.conf file to read the 'Alias' sections > using PHP. Take the one below for example. I have worked out a regex to > get the '/icons/' and the path [eregi('^alias (\/[a-z0-9]+/) > "([a-z:/ ]+)"',trim($line),$regs)] and that works fine, however what I now > want to do is match everything in the <Directory></Directory> section below > that. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|