別の質問の助けを借りて、xpath を使用して Web サイトからクエリを返しましたが、特定のタイトルを検索する必要があります。
これまでの私のコードは次のとおりです。
<?php
libxml_use_internal_errors(true);
$dom = new DomDocument;
$dom->loadHTMLFile("http://www.example.com");
$xpath = new DomXPath($dom);
$nodes = $xpath->query("//span[@class='newprodtext' and contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'adidas')][1]");
foreach ($nodes as $i => $node) {
echo "Node($i): ", $node->nodeValue, "\n";
}
?>
これはサンプル HTML です。
<td colspan="2" align="center">
<a href="product.html" style="text-decoration:none">
<span class="newprodtext">Nike Shoes</span>
</a>
</td>
<td colspan="2" align="center">
<a href="product.html" style="text-decoration:none">
<span class="newprodtext">Nike T-Shirt</span>
</a>
</td>
<td colspan="2" align="center">
<a href="product.html" style="text-decoration:none">
<span class="newprodtext">Adidas Shoes</span>
</a>
</td>
たとえば、"Adidas Shoes" を探している場合のように、検索で 2 つの単語を検索する必要があります。クエリで TRUE を返したいのですが、逆の単語 "Shoes Adidas" または小文字の "shoes" が見つかった場合にも TRUE を返したいです。正確な文字列ではなく、adidas」。