How to get the value in div in php

(*-*)浩
Release: 2023-02-25 17:48:02
Original
5003 people have browsed it

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>
Copy after login

And I want

<div>
     bla bla bla</div>
     bla bla
Copy after login

So this is the original html

$doc = new DOMDocument();
$doc->loadHTML($buffer);
$id = $doc->getElementById(&#39;product_list&#39;)
Copy after login

Using the php DomDocument class.

$dom = new DOMDocument();

$dom->loadHTML($html);

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

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template