I am trying to make a search function using the combination of DOM, PHP and XML. I got something up and running but the problem is that my search function will only accept exact terms, on top of this am wondering if the method I picked the most efficient
$searchTerm = "Lupe";
$doc = new DOMDocument();
foreach (file('musicInformation.xml')as $node)
{
$xmlString .= trim($node);
}
$doc->loadXML($xmlString);
$records = $doc->documentElement->childNodes;
$records = $doc->getElementsByTagName("musicdetails");
foreach( $records as $record )
{
$artistnames = $record->getElementsByTagName("artistname");
$artistname = $artistnames->item(0)->nodeValue;
$recordnames = $record->getElementsByTagName("recordname");
$recordname = $recordnames->item(0)->nodeValue;
$recordtypes = $record->getElementsByTagName("recrodtype");
$recordtype = $recordtypes->item(0)->nodeValue;
$formats = $record->getElementsByTagName("format");
$format = $formats->item(0)->nodeValue;
$prices = $record->getElementsByTagName("price");
$price = $prices->item(0)->nodeValue;
if($searchTerm == $artistname|| $searchTerm == $recordname || $searchTerm == $recordtype ||$searchTerm == $format || $searchTerm == $price)
{
echo "$artistname - $recordname - $recordtype - $format -$price\n";
}