解决方案 »
- 使用WebCalendar PHP开源程序 出现部分字符 ?的形式
- php初学者问题(表单提交,后按刷新)
- MYSQL官方手册(中文)?
- 请教PHP可以调用DELPHI写的动态库吗?
- 各位高手,请看看我这个问题怎样解决啊?
- 有谁改过discuz论坛吗,我想在下面加一个广告条
- 急急急急急急!!在线等待!请问给别人做一个宣传网站(静态的html),怎么收费???
- 我想把用php编的程序变成乱码,但运行却正常,应怎么样做呢
- 怎样接收复选的下拉匡传来的值<input type=select name=duct_kind multiple>
- PHP 4.2.x 在windows 2000 CGI模式下最基础的东东错误!
- PHP常用的算法有哪些?????知道的告知下,3Q
- 求教在notepad++下快速调试代码片段
跟ID无关。不是JS。是PHP取数据。
you dead!
<div class="show">hello</div>
<span>james</span>
</div>
<div class="superStar" id="test_1">
shit!
<div class="contne">hi</div>
<ul><li>list</li></ul>
</div>';$pattern = '/这里正则如何写/';
preg_match($pattern, $subject, $matches);
print_r($matches);$pattern_1 = '/这里正则如何写/';
preg_match($pattern_1, $subject, $matches);
print_r($matches);分别取到结果如下:
数据一:
you dead!
<div class="show">hello</div>
<span>james</span>数据二:
shit!
<div class="contne">hi</div>
<ul><li>list</li></ul>
preg_match_all('/<div(.*?)>(.*?)<\/div>/i',$str,$match);
echo $match[2][0];//内容A
echo $match[2][1];//内容B
var_dump($match);
[0]=>
array(2) {
[0]=>
string(86) "<div class="superStar" id="test_0">
you dead!
<div class="show">hello</div>"
[1]=>
string(80) "<div class="superStar" id="test_1">
shit!
<div class="contne">hi</div>"
}
[1]=>
array(2) {
[0]=>
string(12) " id="test_0""
[1]=>
string(12) " id="test_1""
}
[2]=>
array(2) {
[0]=>
string(45) "
you dead!
<div class="show">hello"
[1]=>
string(39) "
shit!
<div class="contne">hi"
}
}
echo $match[0][0];
echo '<hr />';
echo $match[0][1];
$subject = '<div class="superStar" id="test_0">
you dead!
<div class="show">hello</div>
<span>james</span>
</div>
<div class="superStar" id="test_1">
shit!
<div class="contne">hi</div>
<ul><li>list</li></ul>
</div>';
preg_match_all('/<div[^>]+>(([^<]*|<(?!div)|(?R))+)<\/div>/us',$subject,$match);
echo $match[0][0];
echo '<hr />';
echo $match[0][1];