0

実際、配列リストに 3 つ以上の単語を含むすべての html 要素を取得しようとしています。

$xp= new DomXPath($myhtmlpage);

近いけど違う!

$xp->query("/* my xpath expression + content +regex + count condition */");

方法は何ですか?

4

1 に答える 1

2

Not entirely fail-proof, but with XPath 1.0, there would be this rather ugly solution, here illustrated for matching p elements containing at least 3 words in sequence "cat", "apple", "tree", "bottle"

.//p[
        (
            number(contains(., "cat")) +
            number(contains(., "apple")) +
            number(contains(., "tree")) +
            number(contains(., "bottle"))
         ) >= 3
     ]
  • contains(., "word") returning a boolean if context node contains desired word
  • converting to 1/0 for true/false using number()
  • summing that up with one expression per word
  • and testing the minimal number of words you want
于 2013-09-21T15:15:58.083 に答える