contont
ppppppp
my link contont
ppppppp
my link contont
ppppppp
my link
The above code, I need to extract all the contents of the container class baby, the structure is not necessarily the case. In other words, I need to extract the contents of a container. Thank you.
Reply content:
contont
ppppppp
my link contont
ppppppp
my link contont
ppppppp
my link
The above code, I need to extract all the contents of the container class baby, the structure is not necessarily the case. In other words, I need to extract the contents of a container. Thank you.
I don't know why everyone wants to use the regular to extract the DOM tree ... The regular is not used to do this ...
When you want to do this ... Do you see a full-heartedly grievance?
It is not good to let the maxima grind ... If you want to extract the DOM tree ... The right way is as follows ...
loadHTML( <<
contont
ppppppp
my link
contont
ppppppp
my link
contont
ppppppp
my link HTML_SECTION);/* make a result array ... */$result = [];/* go through all nodes which have class="baby" ... */foreach( ( new DOMXPath( $doc ) )->query( '//*[@class="baby"]' ) as $element ) /* just push it into the result ... */ $result[] = $doc->saveHTML( $element );/* and print the result out ... */print_r( $result );
The rest of the DOM module I wrote in the previous answer is very clear ... Here is not to repeat the ...
If you are interested, you can take a look ...
As for the title of the question ... For more than 90% of the situation ... The answer is not to use the regular ...
If you insist that you do not need to use the regular ... And the document you are dealing with is the same as in your example ... There are ways to do so ...
.*^\\1
)ism',<<
contont
ppppppp
my link
contont
ppppppp
my link
contont
ppppppp
my link HTML_SECTION, $result_tmp );/* only the first element we need ... */print_r( array_shift( $result_tmp ) );
This method is only available on well-formatted HTML documents ... To determine the corresponding relationship of the label by indentation ...
If it's a confusing HTML document ... Then the regular is powerless to extract the DOM ...
nn ... That's it.
Try Phpquery, https://code.google.com/p/phpquery/.
Introduction can look at http://www.cnblogs.com/in-loading/archive/2012/04/11/2442697.html
$preg = '/\(.*?)\<\/div\>/s';preg_match_all($preg, $html, $match);
I don't know if that's okay ~