<?php
$content=<<<HTML
<table class="listtable bg" height="20" border="0" cellspacing="0" name="adsp_list_post_info_b">
<tr><td class="posttitle faceblue">
<a href="http://bbs.city.tianya.cn/tianyacity/content/41/1/1023300.shtml" target="_blank">不开玩笑了,此贴很郑重,也是最后一帖</a>
</td>
<td class="author">
<a href="http://my.tianya.cn/56403359" target="_blank">霸王龙的春天</a>
</td>
<td class="tviewre w_c">169</td>
<td class="treplay w_c">26</td>
<td class="ttime w_c">9-1 22:53</td>
</tr>
</table>
HTML;$preg='#<td class="author">(.*)</td>#';
preg_match($preg,$content,$arr);
print_r($arr);
?>
这样写打印出来是空的,奇怪
$content=<<<HTML
<table class="listtable bg" height="20" border="0" cellspacing="0" name="adsp_list_post_info_b">
<tr><td class="posttitle faceblue">
<a href="http://bbs.city.tianya.cn/tianyacity/content/41/1/1023300.shtml" target="_blank">不开玩笑了,此贴很郑重,也是最后一帖</a>
</td>
<td class="author">
<a href="http://my.tianya.cn/56403359" target="_blank">霸王龙的春天</a>
</td>
<td class="tviewre w_c">169</td>
<td class="treplay w_c">26</td>
<td class="ttime w_c">9-1 22:53</td>
</tr>
</table>
HTML;$preg='#<td class="author">(.*)</td>#';
preg_match($preg,$content,$arr);
print_r($arr);
?>
这样写打印出来是空的,奇怪
改为:
$preg="#<td[^>]+>(.+?)<\/td>#";
s:如果在修饰符中加入"s",那么默认的"."代表除了换行符以外的任何字符将会变成任意字符,也就是包括换行符!