Home > Backend Development > PHP Tutorial > php正则配备div块,该怎么解决

php正则配备div块,该怎么解决

WBOY
Release: 2016-06-13 13:36:43
Original
1000 people have browsed it

php正则配备div块
$a='

1
2
3
4
';

preg_match_all('/
(.*?)/',$a,$match);
echo '
';<br>var_dump($match);<br><br>请问高手们:网上写的匹配div都是这样写的,但是我写的时候,发现他不能完整的匹配一个div块! 如这个我这个div id=css他的结束/div在3的后面,但是这样写只能到2那里就结束了,有没有什么方法匹配到他自己的div块?<br><br><font color="#e78608">------解决方案--------------------</font><br>http://downloads.sourceforge.net/project/simplehtmldom/simplehtmldom/1.5/simplehtmldom_1_5.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fsimplehtmldom%2Ffiles%2F&ts=1332749181&use_mirror=nchc<br><br>simplehtmldom 类<br>简单、实用、高效<br><br>完全不需要自己去摆弄正则
<br><font color="#e78608">------解决方案--------------------</font><br>
嵌套的标签用递归匹配<br>
Copy after login
PHP code
<?php $str='<div id="css">1<div>2</div>3
Copy after login
4
'; $pattern='#
]*>(([^]*|(?R))*)[^]*>#'; preg_match_all($pattern,$str,$matches); echo $matches[0][0]; //
1
2
3

------解决方案--------------------
探讨
额,那有啥办法,如果是一个页面的代码,我们想把头部和尾部的div去掉,请问有什么好的方案?
Related labels:
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