如何将输出转换为变量,以便我可以交叉引用它以查看它是否与我设置的另一个变量匹配
foreach ($nodes as $i => $node) {
echo $node->nodeValue;
}
我知道这是不正确的并且行不通,但是:
foreach ($nodes as $i => $node) {
$target = $node->nodeValue;
}
$match = "some text"
if($target == $match) {
// Match - Do Something
} else {
// No Match - Do Nothing
}
实际上,这解决了我的问题,但可能不是正确的方法:
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, "\n";
$target[0] = $node->nodeValue;
}
$match = "adidas";
if($target == $match) {
// Match
} else {
// No Match
}