This script works for me, hopefully it will help somebody in the future:
<?php
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<YeastarIPPhoneDirectory>';
$db = new SQLite3('/var/lib/asterisk/astdb.sqlite3');
$results = $db->query('SELECT * FROM astdb;');
while ($row = $results->fetchArray()) {
//find
$find='/cidname/';
if(strpos($row['key'], $find)!==false) {
echo '<DirectoryEntry>';
echo '<Name>'.htmlspecialchars($row['value']).'</Name>';
echo '<Telephone>'.str_replace($find, '', $row['key']).'</Telephone>';
echo '</DirectoryEntry>';
}
}
echo '</YeastarIPPhoneDirectory>';
?>
First run the following command to install SQLite3: apt-get install php5-sqlite