Вот такой пример нашел в FreePBX (AsteriskNow 3.0):
/var/lib/asterisk/agi-bin/directory
<?php
function parse_voicemailconf($filename, &$vmconf, &$section) {
if (is_null($vmconf)) {
$vmconf = array();
}
if (is_null($section)) {
$section = "general";
}
if (file_exists($filename)) {
$fd = fopen($filename, "r");
while ($line = fgets($fd, 1024)) {
if (preg_match("/^\s*(\d+)\s*=>\s*(\d*),(.*),(.*),(.*),(.*)\s*([;#].*)?/",$line,$matches)) {
// "mailbox=>password,name,email,pager,options"
// this is a voicemail line
$vmconf[$section][ $matches[1] ] = array("mailbox"=>$matches[1],
"pwd"=>$matches[2],
"name"=>$matches[3],
"email"=>$matches[4],
"pager"=>$matches[5],
);
// parse options
foreach (explode("|",$matches[6]) as $opt) {
$temp = explode("=",$opt);
if (isset($temp[1])) {
list($key,$value) = $temp;
$vmconf[$section][ $matches[1] ]["options"][$key] = $value;
}
}
} else if (preg_match("/^\s*#include\s+(.*)\s*([;#].*)?/",$line,$matches)) {
// include another file
if ($matches[1][0] == "/") {
// absolute path
$filename = $matches[1];
} else {
// relative path
$filename = dirname($filename)."/".$matches[1];
}
parse_voicemailconf($filename, $vmconf, $section);
} else if (preg_match("/^\s*\[(.+)\]/",$line,$matches)) {
// section name
$section = strtolower($matches[1]);
} else if (preg_match("/^\s*([a-zA-Z0-9-_]+)\s*=\s*(.*?)\s*([;#].*)?$/",$line,$matches)) {
// name = value
// option line
$vmconf[$section][ $matches[1] ] = $matches[2];
}
}
}
}
$directory_file = '/etc/asterisk/voicemail.conf';
$vmconf = array();
$null = null;
parse_voicemailconf($directory_file, $vmconf, $null);
print_r($vmconf);
?>
вывод функции:
php -q /tmp/test.php
Array
(
[general] => Array
(
[emailbody] => ${VM_NAME},\n\nThere is a new voicemail in mailbox ${VM_MAILBOX}:\n\n\tFrom:\t${VM_CALLERID}\n\tLength:\t${VM_DUR} seconds\n\tDate:\t${VM_DATE}\n\nDial *98 to access your voicemail by phone.\nVisit http://AMPWEBADDRESS/recordings/index.php to check your voicemail with a web browser.\n
)
[default] => Array
(
[104] => Array
(
[mailbox] => 104
[pwd] => 123
[name] => 104
[email] => 04@mail.ru
[pager] =>
[options] => Array
(
[attach] => yes
[saycid] => yes
[envelope] => yes
[delete] => yes
)
)
)
)
далее можно обрабатывать массив