Regex读取数组中的表行内容-PHP

Regex读取数组中的表行内容-PHP,php,regex,Php,Regex,是否有任何正则表达式可以读取以下表中的内容,请注意,有许多类似的表,因此我只想读取以下表内容 我想从所有 我的正则表达式看起来像下面这样,但不起作用 $match = preg_replace('~<td width="80" bgcolor="#F3F3E4" align="left">&nbsp;<a onmouseout="ChangeImage(AE1,1)" onmouseover="ChangeImage(AE1,0)" href="/charts/live

是否有任何正则表达式可以读取以下
表中的
内容,请注意,有许多类似的
,因此我只想读取以下
内容

我想从所有

我的正则表达式看起来像下面这样,但不起作用

$match = preg_replace('~<td width="80" bgcolor="#F3F3E4" align="left">&nbsp;<a onmouseout="ChangeImage(AE1,1)" onmouseover="ChangeImage(AE1,0)" href="/charts/livegold.html">GOLD</a></td>#[a-z0-9]{6}~i','',$match[3]);
echo '<table><tr>' . $match . '</tr></table>';
$match=preg#u replace('~#[a-z0-9]{6}~i',''$match[3]);
回显“”$匹配。”;
表格如下所示

 <table width="540" cellspacing="1" cellpadding="0" border="0" align="center">
  <tbody><tr>
    <td width="16" bgcolor="#000000" align="center">&nbsp;</td>
    <td width="80" bgcolor="#000000" align="center"><font size="1" face="Arial, Helvetica, sans-serif" color="#FFFFFF">www.kitco.com</font></td>
    <td width="369" bgcolor="#000000" align="center" colspan="5"><p class="white">The World Spot Price - Asia/Europe/NY markets</p></td>
    <td width="73" bgcolor="#000000" align="right"><a href="/market/lights.html"><img width="39" vspace="0" hspace="0" height="17" border="0" alt="light" src="/images/lightgreen.gif"></a></td>
  </tr>
  <tr>
    <td width="16" bgcolor="#000000" align="center">&nbsp;</td>
    <td width="522" bgcolor="#F3F3E4" align="center" colspan="7"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><font color="GREEN">MARKET IS OPEN</font><br>(Will close in 17 hrs. 41 mins.)<!-- 1486.00--></b></font></td>
  </tr>
  <tr bgcolor="#F3F3E4">
    <td width="16" bgcolor="#000000" align="center">&nbsp;</td>
    <td width="80" bgcolor="#CCCC99" align="center">Metals</td>
    <td width="80" bgcolor="#CCCC99" align="center">Date</td>
    <td width="80" bgcolor="#CCCC99" align="center">Time (EST)</td>
    <td width="68" bgcolor="#CCCC99" align="center">Bid</td>
    <td width="68" bgcolor="#CCCC99" align="center">Ask</td>
    <td width="146" bgcolor="#CCCC99" align="center" colspan="2">Change from NY Close</td>
  </tr>
  <tr bgcolor="#F3F3E4">
    <td width="16" bgcolor="#000000" align="center"><a onmouseout="ChangeImage('AE1','1')" onmouseover="ChangeImage('AE1','0')" href="/charts/livegold.html"><img width="16" vspace="0" hspace="0" height="13" border="0" alt="Gold Charts" name="AE1" src="http://www.kitco.com/images/graph_down.gif"></a></td>
    <td width="80" bgcolor="#F3F3E4" align="left">&nbsp;<a onmouseout="ChangeImage('AE1','1')" onmouseover="ChangeImage('AE1','0')" href="/charts/livegold.html">GOLD</a></td>
    <td width="80" align="center">06/04/2013</td>
    <td width="80" align="center">23:34</td>
    <td width="68" align="center">1405.50</td>
    <td width="68" align="center">1406.50</td>
    <td width="73" align="center"><p class="spotgreen">+5.50</p></td>
    <td width="73" align="center"><p class="spotgreen">+0.39%</p></td>
  </tr>
  <tr bgcolor="#F3F3E4">
    <td width="16" bgcolor="#000000" align="center"><a onmouseout="ChangeImage('AE2','1')" onmouseover="ChangeImage('AE2','0')" href="/charts/livesilver.html"><img width="16" vspace="0" hspace="0" height="13" border="0" alt="Silver Charts" name="AE2" src="http://www.kitco.com/images/graph_down.gif"></a></td>
    <td width="80" align="left">&nbsp;<a onmouseout="ChangeImage('AE2','1')" onmouseover="ChangeImage('AE2','0')" href="/charts/livesilver.html">SILVER</a></td>
    <td width="80" align="center">06/04/2013</td>
    <td width="80" align="center">23:34</td>
    <td width="68" align="center">22.59</td>
    <td width="68" align="center">22.69</td>
    <td width="73" align="center"><p class="spotgreen">+0.05</p></td>
    <td width="73" align="center"><p class="spotgreen">+0.20%</p></td>
  </tr>
  <tr bgcolor="#F3F3E4">
    <td width="16" bgcolor="#000000" align="center"><a onmouseout="ChangeImage('AE3','1')" onmouseover="ChangeImage('AE3','0')" href="/charts/liveplatinum.html"><img width="16" vspace="0" hspace="0" height="13" border="0" alt="Platinum Charts" name="AE3" src="http://www.kitco.com/images/graph_down.gif"></a></td>
    <td width="80" align="left"><p>&nbsp;<a onmouseout="ChangeImage('AE3','1')" onmouseover="ChangeImage('AE3','0')" href="/charts/liveplatinum.html">PLATINUM</a></p></td>
    <td width="80" align="center">06/04/2013</td>
    <td width="80" align="center">23:34</td>
    <td width="68" align="center">1501.00</td>
    <td width="68" align="center">1509.00</td>
    <td width="73" align="center"><p class="spotgreen">+9.00</p></td>
    <td width="73" align="center"><p class="spotgreen">+0.60%</p></td>
  </tr>
  <tr bgcolor="#F3F3E4">
    <td width="16" bgcolor="#000000" align="center"><a onmouseout="ChangeImage('AE4','1')" onmouseover="ChangeImage('AE4','0')" href="/charts/livepalladium.html"><img width="16" vspace="0" hspace="0" height="13" border="0" alt="Palladium Charts" name="AE4" src="http://www.kitco.com/images/graph_down.gif"></a></td>
    <td width="80" align="left">&nbsp;<a onmouseout="ChangeImage('AE4','1')" onmouseover="ChangeImage('AE4','0')" href="/charts/livepalladium.html">PALLADIUM</a></td>
    <td width="80" align="center">06/04/2013</td>
    <td width="80" align="center">23:25</td>
    <td width="68" align="center">755.00</td>
    <td width="68" align="center">761.00</td>
    <td width="73" align="center"><p class="spotgreen">+6.00</p></td>
    <td width="73" align="center"><p class="spotgreen">+0.80%</p></td>
  </tr>
</tbody></table>    

www.kitco.com

世界现货价格-亚洲/欧洲/纽约市场

市场开放
(将在17小时41分钟后关闭。) 金属 日期 时间(东部标准时间) 投标 问 从纽约到纽约的转变 06/04/2013 23:34 1405.50 1406.50

+5.50

+0.39%

06/04/2013 23:34 22.59 22.69

+0.05

+0.20%

06/04/2013 23:34 1501 1509

+9.00

+0.60%

06/04/2013 23:25 755 761

+6.00

+0.80%

这是我要提取的数据


您可以使用一些HTML解析器。对于PHP,有一个


将DOM加载到库中后,通过
元素并迭代每个
TR
元素。

确定以下是正则表达式的解决方案:

$patt = "/<td[^>]*width=['\"]68['\"][^>]*>([0-9\.]+)<\/td>\s*<td[^>]*width=['\"]68['\"][^>]*>([0-9\.]+)<\/td>/i";
if(preg_match_all($patt, $html, $matches))
{
   //print all records
   //print_r($matches);

   for($i=0; $i<count($matches[1]); $i++)
   {

       echo "Bid: ".$matches[1][$i].", Ask: ".$matches[2][$i]."\n";

   }

}
$patt=“/]*width=['\']68['\'][^>]*>([0-9\.]+)\s*]*width=['\'\']68['\'\'][^>]*>([0-9\.]+)/i”;
if(preg_match_all($patt,$html,$matches))
{
//打印所有记录
//打印(匹配项);

对于($i=0;$i“是否有任何正则表达式可读取…”是的,也许吧。我们可以帮助您完成当前的正则表达式尝试…什么不起作用?也检查一下这个著名的答案,以防万一。@elclanrs添加了当前的正则表达式regex@user580950-你想提取哪些数据?举一个+1的例子。也许有人能帮上忙。像下面建议的答案那样使用DOM解析器怎么样?@RobinVanPersi我想从3中读取数据,所有TRsGreat的4,5 TD显示黄金、白银行的出价、要价,但不显示铂金、钯金的出价、要价请告知