php - Search for substrings of text in a node in a XML file -
i have php found in q&a forum queries xml file:
$doc = new domdocument; // create new dom document $doc->preservewhitespace = false; // set features $doc->formatoutput = true; // create indents on xml $doc->load('i.xml'); // load file $xpath = new domxpath($doc); $query = '//users/user/firstname[.= "'.$_post["search"].'"]'; // xpath (starts root node) $names = $xpath->query($query); // list of matched elements $output=""; foreach ($names $node) { $output.=$doc->savexml($node->parentnode)."\n"; // parent of "<firstname>" element (the entire "<user>" node , children) (maybe parent node directly using xpath) // , use savexml() convert string } echo $output."<br>\n\n"; // result echo "<hr><br><b>below view results html content. (see page's html code):</b>\n<pre>".htmlspecialchars($output)."</pre>";
the script search values of firstname
nodes in xml document input post
, , return parent node of nodefirstname
, if post
input value matches of node values.
this script works well, returns queries contain entire value of firstname
node, , not work if search substring of node's text (e.g query potato
return potato
, query pot
, not give me results potato
).
so how result contains substring of node's text, instead of entire value ?
Comments
Post a Comment