【问题标题】:preg match not reading content between table预匹配不读取表之间的内容
【发布时间】:2010-07-12 11:14:26
【问题描述】:
preg_match_all('|<table cellspacing="0" cellpadding="0" summary="Flight Timetable search results" id="timeTable">(.*?)</table>|', $read, $foo, PREG_SET_ORDER);
print_r($foo);

直接输出

数组( )

哪里出错了

见人,

其实我想从这个URL获取确切的细节

我想从这个 URL 中选择这个细节

08:35 9W5048 TORONTO EXPECTED 1358 Terminal 3

所以我尝试了这个 sn-p ,但它抛出了像

这样的错误

这是我的sn-p

$read = file_get_contents("http://www.heathrowairport.com/portal/site/heathrow/template.PAGE/menuitem.a43f3a72926ca3b1b0c52a499328c1a0/?javax.portlet.begCacheTok=token&javax.portlet.endCacheTok=token&javax.portlet.tpst=bde211e38117ef94303fde9faca12635&javax.portlet.prp_bde211e38117ef94303fde9faca12635_flightRoute=&javax.portlet.prp_bde211e38117ef94303fde9faca12635_flightNumber=9W5048&javax.portlet.prp_bde211e38117ef94303fde9faca12635_flightTerminal="); //回显 $read; preg_match_all('/(.?)/si', $read, $foo, PREG_SET_ORDER); $read1 = $foo[0][0]; preg_match_all('/(.?)/si', $read1, $foo1, PREG_SET_ORDER); print_r($foo1[0][0]);

我得到了类似的错误

注意:未定义的偏移量:第 6 行 E:\wamp\www\plugin\read-airport-arraiwals.php 中的 0 注意:未定义的偏移量:第 8 行 E:\wamp\www\plugin\read-airport-arraiwals.php 中的 0

【问题讨论】:

标签: preg-match preg-match-all php


【解决方案1】:
preg_match_all('/timeTable" .*<tbody>(.*?)<\/table>/smU', $read, $foo, PREG_SET_ORDER);
preg_match_all('/<(th|td).*>(.*)<\/(th|td)>/smU', $foo[0][1], $result, PREG_SET_ORDER);
print_r($result);

您将获得所需的数据。快速回答,因为我没有时间为此创建一个模式,但是这个可以完成这项工作。

【讨论】:

  • 是否可以让数组变得非常简单,即一维数组中的值
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-06
  • 1970-01-01
  • 2021-09-24
  • 1970-01-01
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多