How do I turn the output into a variable so i can cross reference it to see if it matches another variable I have set
foreach ($nodes as $i => $node) {
echo $node->nodeValue;
}
I know this is incorrect and wouldn't work but:
foreach ($nodes as $i => $node) {
$target = $node->nodeValue;
}
$match = "some text"
if($target == $match) {
// Match - Do Something
} else {
// No Match - Do Nothing
}
Actually this solves my question but maybe not the right way about it:
libxml_use_internal_errors(true);
$dom = new DomDocument;
$dom->loadHTMLFile("http://www.example.com");
$xpath = new DomXPath($dom);
$nodes = $xpath->query("(//tr/td/a/span[@class='newprodtext' and contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'adidas')])[1]");
foreach ($nodes as $i => $node) {
echo $node->nodeValue, "
";
$target[0] = $node->nodeValue;
}
$match = "adidas";
if($target == $match) {
// Match
} else {
// No Match
}