Home  >  Article  >  Backend Development  >  How to get the value in div in php

How to get the value in div in php

(*-*)浩
(*-*)浩Original
2019-09-30 13:33:315002browse

I have a div in php (string) and I want to get the content.

How to get the value in div in php

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(&#39;product_list&#39;)

Using the php DomDocument class.

$dom = new DOMDocument();

$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$divContent = $xpath->query(&#39;//div[id="product_list"]&#39;);

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn