I've inherited some php that parses an xml file to populate a page full of unordered lists and am wondering if there is a way to consolidate the php functions to make them more efficient.
There are 25 or so functions like the following:
function oaAccounting(){
// load SimpleXML
$term = new SimpleXMLElement('training_list.xml', null, true);
echo <<<EOF
<ul>
EOF;
foreach($term as $term)
{
if(preg_match("/accounting/i", $term->keyword)){
echo <<<EOF
<li>{$term->name}</li>
EOF;
}
}
echo '</ul>';
}
each one scans the xml file for the term/keyword it's searching for and adds the term as a list element to an unordered list specific to that function. The next function does the same thing but for a different term/keyword and adds it to a separate unordered list.
is there a way to combine all this to prevent having to do the foreach and if 25 times in a row?
Thanks!
$termis overwritten in every iteration? And why regular expressions? XML has xpath for that.