Search code examples
xpathphpdomxpath

Using xpath with 'contains' in php


I have:

<div class="posts">
    <p class="post">info: abcd</p>
    ....
</div>

I am trying to use xpath to select the

containing "info: abcd"

I have:

$DNlist = $xpath->query("//div[@class='posts']/p[contains(., 'info:')]]");

This gives:

Severity: Warning
Message: DOMXPath::query(): Invalid expression

How can I fix this?


Solution

  • There seems to be on square bracket (]) to much. Try:

    "//div[@class='posts']/p[contains(., 'info:')]"