<div class="c_list">
<ul>
<li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
<li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
<li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
</ul>
用正则获取出每个li中<a></a> 之间数据,不知道哪出错了,有点乱,希望高手指点下
我写了没有数据
$pattern = "/^<div class=\"c_list\">([\r\n][\s]+)<ul>([\r\n][\s]+)<li>·(<([\w]+)[^>]*>)(.*)(<\/\\2>)/";
preg_match_all($pattern, $results,$matches);
echo '<pre>';
var_dump($matches);
<ul>
<li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
<li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
<li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
</ul>
用正则获取出每个li中<a></a> 之间数据,不知道哪出错了,有点乱,希望高手指点下
我写了没有数据
$pattern = "/^<div class=\"c_list\">([\r\n][\s]+)<ul>([\r\n][\s]+)<li>·(<([\w]+)[^>]*>)(.*)(<\/\\2>)/";
preg_match_all($pattern, $results,$matches);
echo '<pre>';
var_dump($matches);
解决方案 »
- 两份PHP程序代码对比,大家认为其编程水平都怎么样?censor.class.php
- cookie文件里的时间转换为unix时间问题
- php-cgi.exe怎样加到windows服务里面
- xml创建和解析问题
- ZEND提示Undefined variable: vals_!
- ckeditor放在apache目录里,报错ckeditor未定义【求助】
- smarty 上传时的问题,急!!!
- 有人知道PHP5文件夹里哪儿有php5ts.dll这个文件吗?不胜感谢!!
- 如何在不刷新页面时,点击时执行php代码
- [求助帖]Warning: mysql_num_rows()
- 网页视频打不开
- 昨天那个sql查询周查询又不行了,进来看看,汗- -!
<div class="c_list">
<ul>
<li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
<li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
<li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
</ul>HTML;$p = '/<a.+<\/a>/isU';preg_match_all($p, $s, $r);
print_r($r);
Array
(
[0] => Array
(
[0] => <a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a>
[1] => <a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a>
[2] => <a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a>
))
<div class="c_list">
<ul>
<li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
<li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
<li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
</ul>
$str=<<< EOF
<div class="c_list">
<ul>
<li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
<li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
<li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
</ul>
EOF;
preg_match("/<div\s+class=\"c_list\">.+<\/ul>/isU",$str,$matchs);
preg_match_all('/<a.+<\/a>/isU',$matchs[0],$arr);
print_r($arr);
Array
(
[0] => Array
(
[0] => <a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a>
[1] => <a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a>
[2] => <a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a> ))
$str = <<<STR
<div class="c_list">
<ul>
<li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
<li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
<li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
</ul>STR;
preg_match_all('/<a[^>]*>(.*)<\/a>/Ui', $str, $matches);
print_r($matches[1]);
/*
输出结果:
Array
(
[0] => 111<b class="ger_1">1</b>硬功夫
[1] => 222<b class="ger_1">2</b> 左在
[2] => 333<b class="ger_1">3</b>在地
)*/
$str = '<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a>';
preg_match_all("/<[\w]+[^>]*>(.*)<[\w]+[^>]*>(.*)<\/b>(.*)<\/a>/isU",$str,$arr);
echo '<pre>';
print_r($arr);Array
(
[0] => Array
(
[0] => 1111硬功夫
) [1] => Array
(
[0] => 111
) [2] => Array
(
[0] => 1
) [3] => Array
(
[0] => 硬功夫
))
/怎么写可以取得上面这样的结果,参照了下php手册的写法,但是对整个的写法还不是很清楚,要明了点,最好能带点注释,谢谢
<div class="c_list">
<ul>
<li>·<a href="http://www.xxxxxx.html" target="_blank">111<b class="ger_1">1</b>硬功夫</a></li>
<li>·<a href="http://www.xxxx2.html" target="_blank">222<b class="ger_1">2</b> 左在 </a></li>
<li>·<a href="http://www.xxx3.html" target="_blank">333<b class="ger_1">3</b>在地 </a></li>
</ul>