用preg_match_all("/<td[\s\S][(align=\"right\")|(width=\"480\")>](.*)[\s]*<\/td>/siU", $filecontent, $matches);得到的就是
[0] => idth="120" class="TDTitle" align="right">名称
[1] => idth="480">数据
…………
而不是单纯的
[0] => 名称
[1] => 数据
…………
请问怎么实现?
[0] => idth="120" class="TDTitle" align="right">名称
[1] => idth="480">数据
…………
而不是单纯的
[0] => 名称
[1] => 数据
…………
请问怎么实现?
代码:
===================
<?php
$content = '<table width="100%" height="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td valign="top">
<table width="600" border="3" align="center" cellpadding="2" cellspacing="0">
<tr height="25">
<td width="120" class="TDTitle">名称</td>
<td width="480">数据</td>
</tr>
<tr height="25">
<td width="120" class="TDTitle">名称</td>
<td width="480">数据</td>
</tr>
<!--重复上面的两列n行格式-->
</table>
</td>
</tr>
</table>';
preg_match_all("/<td width=\"120\" class=\"TDTitle\">(.*)<\/td>.*<td width=\"480\">(.*)<\/td>/isU", $content, $matches);
print_r($matches);
?>
===================
---------- 程序调试 ----------
Array
(
[0] => Array
(
[0] => <td width="120" class="TDTitle">名称</td>
<td width="480">数据</td>
[1] => <td width="120" class="TDTitle">名称</td>
<td width="480">数据</td>
) [1] => Array
(
[0] => 名称
[1] => 名称
) [2] => Array
(
[0] => 数据
[1] => 数据
))Output completed (0 sec consumed) - Normal Termination
稻草人
请问哈你们的环境是?
我的preg_match_all("/<td width=\"120\" class=\"TDTitle\">(.*)<\/td>.*<td width=\"480\">(.*)<\/td>/isU", $content, $matches)得到一个空数组
?
用preg_match_all("/<td[\s\S][(align=\"right\")|(width=\"480\")>](.*)[\s]*<\/td>/siU", $filecontent, $matches);得到的就是
[0] => idth="120" class="TDTitle" align="right">名称
[1] => idth="480">数据
…………
而不是单纯的
[0] => 名称
[1] => 数据
…………
请问怎么实现?
======
第一个都是原来匹配的整个值
你把第一个去掉就行了
$matches = array($matches[1],$matches[2]);
print_r($matches);