Tutorial :preg match not reading content between table



Question:

preg_match_all('|<table cellspacing="0" cellpadding="0" summary="Flight Timetable search results" id="timeTable">(.*?)</table>|', $read, $foo, PREG_SET_ORDER);  print_r($foo);  

output as just

Array ( )

Where i made mistake

See guys ,

Actually i want to grab the exact details from this URL

i want to pick this details from this URL

08:35 9W5048 TORONTO EXPECTED 1358 Terminal three

So i tried this snippet , but it throwing Error like

this is my snippet

$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="); //echo $read; preg_match_all('/(.?)</table>/si', $read, $foo, PREG_SET_ORDER); $read1 = $foo[0][0]; preg_match_all('/(.?)</tbody>/si', $read1, $foo1, PREG_SET_ORDER); print_r($foo1[0][0]);

I got Error like

  Notice: Undefined offset: 0 in E:\wamp\www\plugin\read-airport-arraiwals.php on line 6    Notice: Undefined offset: 0 in E:\wamp\www\plugin\read-airport-arraiwals.php on line 8  


Solution: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);  

And you will get the required data. Quick answer because I don't have time to create a single pattern for that, but this one will do the job.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »