Home > Backend Development > PHP Tutorial > 字符串截取解决方案

字符串截取解决方案

WBOY
Release: 2016-06-13 12:40:30
Original
961 people have browsed it

字符串截取

$subject = '<div class="superStar" id="test_0"><br />
 				you dead!<br />
				<div class="show">hello</div><br />
				<span>james</span><br />
			</div><br />
            <div class="superStar" id="test_1"><br />
				shit!<br />
				<div class="contne">hi</div><br />
				<ul><li>list</li></ul><br />
            </div>';<br />
<br />
$pattern = '/这里正则如何写/';<br />
preg_match($pattern, $subject, $matches);<br />
print_r($matches);<br />
<br />
$pattern_1 = '/这里正则如何写/';<br />
preg_match($pattern_1, $subject, $matches);<br />
print_r($matches);<br />
<br />
分别取到结果如下:<br />
数据一:<br />
you dead!<br />
<div class="show">hello</div><br />
<span>james</span><br />
<br />
数据二:<br />
shit!<br />
<div class="contne">hi</div><br />
<ul><li>list</li></ul>
Copy after login


请问正则要如何写才能取出上在的两个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