Home > Article > Backend Development > How to get the value in div in php
I have a div in php (string) and I want to get the content.
For example: (Recommended learning: PHP video tutorial)
<div id="product_list" style="width:100%; float:none;"> <div> bla bla bla </div> bla bla </div>
And I want
<div> bla bla bla</div> bla bla
So this is the original html
$doc = new DOMDocument(); $doc->loadHTML($buffer); $id = $doc->getElementById('product_list')
Using the php DomDocument class.
$dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $divContent = $xpath->query('//div[id="product_list"]');
The above is the detailed content of How to get the value in div in php. For more information, please follow other related articles on the PHP Chinese website!