正则问题 <div id=\"list-new\">.+?<\/tr>\s+<tr>(?:\s+<td.+?>(.+?)<\/td>){6}大家看看我的这个正则为什么匹配的都是最后一个<td>的值呢?为什么没有把匹配的值一个个获取呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?$str='<div id="list-new"> <table> <tr> <th class="edit">ID </th> <th class="edit">name </th> <th class="edit" style="width:70px">title </th> <th class="edit">content </th> <th class="edit" style="width:100px">time </th> <th class="edit" style="width:220px">desc </th> </tr> <tr> <td class="edit"> <a href="http://abc.com/aa.php?id=777" target="_blank">7777777777 </a> </td> <td class="edit">10 </td> <td class="edit" style="width:70px">你好吗 </td> <td class="edit">vip </td> <td class="edit" style="width:100px">2008-09-10 11:13 </td> <td class="edit" style="width:220px">OK </td> </tr> <tr> <td class="edit"> <a href="http://abc.com/getuser.do?id=333333333333" target="_blank">3333333333333 </a> </td> <td class="edit">120 </td> <td class="edit" style="width:70px">sisisi </td> <td class="edit">abvc </td> <td class="edit" style="width:100px">2008-09-10 12:12 </td> <td class="edit" style="width:220px">很好啊 </td> </tr> </table> ';$reg = '/<tr>(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)<\/tr>/is';preg_match_all($reg, $str, $res);print_r($res);?> 这么匹配的html代码,为什么不尝试dom$str='<div id="list-new"> <table> <tr> <th class="edit">ID </th> <th class="edit">name </th> <th class="edit" style="width:70px">title </th> <th class="edit">content </th> <th class="edit" style="width:100px">time </th> <th class="edit" style="width:220px">desc </th> </tr> <tr> <td class="edit"> <a href="http://abc.com/aa.php?id=777" target="_blank">7777777777 </a> </td> <td class="edit">10 </td> <td class="edit" style="width:70px">你好吗 </td> <td class="edit">vip </td> <td class="edit" style="width:100px">2008-09-10 11:13 </td> <td class="edit" style="width:220px">OK </td> </tr> <tr> <td class="edit"> <a href="http://abc.com/getuser.do?id=333333333333" target="_blank">3333333333333 </a> </td> <td class="edit">120 </td> <td class="edit" style="width:70px">sisisi </td> <td class="edit">abvc </td> <td class="edit" style="width:100px">2008-09-10 12:12 </td> <td class="edit" style="width:220px">你好吗 </td> </tr> </table></div>';$str = utf8_encode($str);$dom = simplexml_load_string($str);echo utf8_decode(htmlspecialchars($dom->table[0]->tr[1]->asXML())); $search = array( '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@ @' preg_match("/<td.*?>(.+?)<\/td>/",$text,$matches);print_r($matches[1]); preg_match_all("/ <td.*?>(.+?) <\/td>/",$text,$matches); print_r($matches[1]); 求 wordpress问题.根据文章id得到该文章评论的请求方式 PHP中 session 丢失的问题 求几道面试题(急) php程序换行,怎写? $_POST怎么总把我的"'"转换为"\'", 请问如何解决? phpmysql查询问提 怎么用php获得由javascript得到的值 运行phpmyadmin,但却再现这样的提示,什么意思 高手,如何在单机上测试编好的PHP聊天室? ftp函数问题,请各位帮忙指正! zendStudio js不能保存中文 取最后一个值的正则表达式问题
$str='<div id="list-new">
<table>
<tr>
<th class="edit">ID </th>
<th class="edit">name </th>
<th class="edit" style="width:70px">title </th>
<th class="edit">content </th> <th class="edit" style="width:100px">time </th>
<th class="edit" style="width:220px">desc </th>
</tr> <tr>
<td class="edit"> <a href="http://abc.com/aa.php?id=777" target="_blank">7777777777 </a> </td>
<td class="edit">10 </td>
<td class="edit" style="width:70px">你好吗 </td>
<td class="edit">vip </td> <td class="edit" style="width:100px">2008-09-10 11:13 </td>
<td class="edit" style="width:220px">OK </td>
</tr> <tr>
<td class="edit"> <a href="http://abc.com/getuser.do?id=333333333333" target="_blank">3333333333333 </a> </td>
<td class="edit">120 </td>
<td class="edit" style="width:70px">sisisi </td>
<td class="edit">abvc </td> <td class="edit" style="width:100px">2008-09-10 12:12 </td>
<td class="edit" style="width:220px">很好啊 </td>
</tr>
</table> ';
$reg = '/<tr>(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)(?:\s*<td.*?>(.+?)<\/td>\s*)<\/tr>/is';
preg_match_all($reg, $str, $res);
print_r($res);
?>
<table>
<tr>
<th class="edit">ID </th>
<th class="edit">name </th>
<th class="edit" style="width:70px">title </th>
<th class="edit">content </th> <th class="edit" style="width:100px">time </th>
<th class="edit" style="width:220px">desc </th>
</tr> <tr>
<td class="edit"> <a href="http://abc.com/aa.php?id=777" target="_blank">7777777777 </a> </td>
<td class="edit">10 </td>
<td class="edit" style="width:70px">你好吗 </td>
<td class="edit">vip </td> <td class="edit" style="width:100px">2008-09-10 11:13 </td>
<td class="edit" style="width:220px">OK </td>
</tr> <tr>
<td class="edit"> <a href="http://abc.com/getuser.do?id=333333333333" target="_blank">3333333333333 </a> </td>
<td class="edit">120 </td>
<td class="edit" style="width:70px">sisisi </td>
<td class="edit">abvc </td> <td class="edit" style="width:100px">2008-09-10 12:12 </td>
<td class="edit" style="width:220px">你好吗 </td>
</tr>
</table>
</div>';$str = utf8_encode($str);
$dom = simplexml_load_string($str);
echo utf8_decode(htmlspecialchars($dom->table[0]->tr[1]->asXML()));
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@ @'
print_r($matches[1]);
print_r($matches[1]);