Regex to match ALL characters?

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-15-2003
Linda Patterson
 
Posts: n/a
Default Regex to match ALL characters?

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/


Reply With Quote
  #2 (permalink)  
Old 07-16-2003
stephan beal
 
Posts: n/a
Default Re: Regex to match ALL characters?

Linda Patterson wrote:
> 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 '.'


Don't do that. Use the 'm' option for preg_match, which makes . match a \n.

http://www.php.net/manual/en/ref.pcre.php
http://www.php.net/manual/en/pcre.pattern.modifiers.php

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:52 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0