php正则匹配嵌套<div>标签的有关问题
Jun 13, 2016 am 11:50 AM
div
gt
lt
nbsp
php
php正则匹配嵌套
标签的问题
php新手, 最近用php写正则匹配 遇到了一个问题
楼主用 preg_match 函数 在php正则匹配网页
这时如果遇到 div 嵌套
就会在第一个
标签结束php新手, 最近用php写正则匹配 遇到了一个问题
楼主用 preg_match 函数 在php正则匹配网页
标签时 想通过特定的id匹配,
即获取
表示结束即获取
...
这段内容 楼主采用的正则是 判断到这时如果遇到 div 嵌套
<div id="目标id"><br /> <!--中间有不确定数目的<div>标签--><br /> <div><br /> </div> <!--楼主的方法在这里匹配结束--><br /> <div><br /> </div><br /> <!--.......--><br /></div>
Copy after login
就会在第一个
求问php里怎么样解决?。。
或者有没有现成的可以通过 标签 id来获取标签内所有内容的函数 或者库?
楼主更加希望php有函数或者库可以一下子拿到整个标签内容 而不要自己手动些正则,平时用python和java比较多,比较懒。。
刚接触php 不太了解 如果能推荐一些比较好的学习网站不甚感激。
------解决方案--------------------
$s =<<< TXT<br /><div id="tid"><br /> <!--中间有不确定数目的<div>标签--><br /> <div><br /> </div> <!--楼主的方法在这里匹配结束--><br /> <div><br /> </div><br /> <!--.......--><br /></div><br />TXT;<br />$s = iconv('gbk', 'utf-8', $s); //如果是 utf-8 的就不需要了<br /><br />require('phpQuery.php');<br />$doc = phpQuery::newDocument($s);<br />//echo $doc->find('#tid')->html(); //可以这样写<br />echo pq('#tid')->html(); //也可以这样写<br />
Copy after login
<!--中间有不确定数目的<div>标签--><br /> <div><br /> </div> <!--楼主的方法在这里匹配结束--><br /> <div><br /> </div><br /> <!--.......-->
Copy after login
用正则也可以,但每次都要绞尽脑汁,有点得不偿失
而用 phpQuery 类则是只需会用 js 的 jQuery 就行了
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

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
