Answer the question
In order to leave comments, you need to log in
How to use XPath to find the contents of a container with a class?
Good afternoon!
It is necessary to find all containers with the `auto-formatting` class in the body of the body tag and process them.
I'm looking like this:
preg_match( '/\<div class\=\"auto-formatting\"\>([\s\S]*?)\<\/div\>\<\!-- \.auto-formatting --\>/miu', func_get_arg(0), $matches );
$i = 0;
$html = DOMDocument::loadHTML( $buffer );
$xpath = new DOMXPath($htmll);
foreach( $xpath->query('//div[contains(@class,"auto-formatting")]') as $item ) {
// обработка
$i++;
}
Answer the question
In order to leave comments, you need to log in
The expression is correct. There is a typo in the code. The DOM is loaded into the $html variable, and the XPath is applied to the document from the $html l variable . In general, if $htmll was not initialized, then it should have failed with an error. In general, it is worth turning on the display of errors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question