- var_dump: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$regex = '/<\S+\s*\S*>[\s\S]*?(?:<\/\S+>)|([\s\S]+\n*)/';
$vhost = '
DocumentRoot /www/example2
ServerName www.example.org
ErrorLog /var/log/log.txt
<Directory>
ErrorLog /var/log/log.txt
</Directory>
<Directory />
ErrorLog /var/log/log.txt
</Directory>';
preg_match_all($regex, $vhost, $matches);
var_dump($matches);