日期:2014-05-17  浏览次数:20422 次

正则匹配函数
本帖最后由 Jackdowson123 于 2013-06-22 00:36:32 编辑
$data=mb_convert_encoding($data, "utf-8", "gb2312");
    preg_match_all ( '/\>(\-?\d+\.\d+)\<\/font\>/', $data, $matches );
return var_dump($matches);



其中$data='<html>
<head>
<title>寝室电量剩余查询结果</title>
</head>
<body bgcolor="#FFFFE9" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br>
<center><br><br><br><br><br><font size=5 color='#000066' face=黑体><table  width='80%' border='1' align='center' cellpadding='4' cellspacing='0' bgcolor='#FFFFF1'><tr><td width='80%'><center><br><font size=5 color='#000066' face=黑体>截止<font color='#000099'>今天</font>上午9:00, </font></font><font size=5 color='#000066' face=黑体>22栋416寝室电量剩余:<FONT size=5 color='#009933' face=黑体>20.34</FONT> 度.</font>
<font size=3 color='#000066' face=黑体><br><br><br>(查询操作执行时间: 2013-6-21&nbsp;11:49)<br></font><br></center></td></tr></table><br><table bgcolor='#FFFFE9'  width='80%' border='0' align='center' cellpadding='4' cellspacing='0' bgcolor='#FFFFF1'><tr><td width='80%'><br><font size=2 color='#000077' >说明:<br> &nbsp;&nbsp;&nbsp;&nbsp;(1)正常情况下,用电管理系统每天上午9:00-9:30自动抄表,得到前一天上午9:00以来的用电量,并计算电量剩余,如果剩余电量小于等于0度,则会停止供电等待用户续交电费。<br>&nbsp;&nbsp;&nbsp;&nbsp;(2)续交电费后,系统一般在10分钟后供电。</font></td></tr></table>

<br><br>
<a href="javascript:window.opener=null;window.close();">关 闭</a>
<br><br><br>
<p><font size=2 color='#000066' 学生公寓办  邮编:445000. Email:chensq8808@yahoo.com.cn-</font>
</center>
</body>
</html>
'

为什么这里返回的是空值,而如果$data='<FONT size=5 color='#009933' face=黑体>20.34</FONT> 度.</font>',却可以返回20.34.有没有人知道什么原因啊
正则 HTML

------解决方案--------------------
preg_match_all ( '/\>(\-?\d+\.\d+)\<\/font\>/i', $data, $matches );

i 忽略大小写