1

First see this commented tag that is for apache virtualHost config file:

##<VirtualHost *:80>
    ##ServerAdmin postmaster@dummy-host2.localhost
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
    ##ServerName dummy-host2.localhost
    ##ServerAlias www.dummy-host2.localhost
    ##ErrorLog "logs/dummy-host2.localhost-error.log"
    ##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</VirtualHost>

How can find uncommented tags and get content between theme?

4

2 回答 2

2

将此正则表达式^\s*[^#\s].+?$与正则表达式选项一起使用,multyline您可以捕获 matchCollection 未注释的行

于 2012-07-13T19:06:30.467 回答
2
$subject = '##<VirtualHost *:80>
##ServerAdmin postmaster@dummy-host2.localhost
##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
##ServerName dummy-host2.localhost
##ServerAlias www.dummy-host2.localhost
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</VirtualHost>';

$pattern = '=[#]{1,}<VirtualHost.[^>]*>(.*?)</VirtualHost>=is';
$result = preg_match_all($pattern, $subject, $matches);

echo '<pre>'.print_r($matches, true).'</pre>';

在 $matches[1] 你会找到你要找的

于 2012-07-13T19:14:25.357 回答