Jump to content

Parse bus plan, please help.


cordoprod

Recommended Posts

Hey, i'm trying to parse a web page containing bus plans.

It is this site: http://www.rutebok.no/NRIIISStaticTables/Tables/ruter/index/Avd_01.htm

 

What I want to parse is all the rutenr and rutenavn.

 

The plans are divided into section as you can see there are tabs on the top of the page. This does not make it easy for me, as I have to separate them.

 

Here is what I managed to pull out:

http://ruteinfo.cordoproduction.com/hent_ruter.php?avdeling=01&fylke=Ostfold

 

Here is my code:

$htmlCode = file_get_contents("http://www.rutebok.no/NRIIISStaticTables/Tables/ruter/index/Avd_".$avdeling.".htm");

$linjer = preg_match_all('/\["([\pL ]+)",/', $htmlCode, $linjerMatches);
//$type = preg_match_all('/(.*\/images\/)(.*)(-s.gif)/', $htmlCode, $typeMatches);
$tabeller = preg_match_all('/(.*\d\d\-\d\d\d\.htm">)(\d\d\-\d\d\d)(.*px">)(.*)(<\/td>.*)/', $htmlCode, $matches);

foreach($linjerMatches[1] as $k=>$v) {
echo '<h2>' . $linjerMatches[1][$k] . '</h2>';	

foreach($matches[2] as $key=>$value) {
   		if(mysql_num_rows($checkResult) == 0) { 
		echo '<b>' . $value . '</b> ' . $matches[4][$key] . ' <b>' . $linjerMatches[1][$k] . '</b><br/>';

		//$sql = "INSERT INTO ruteinfo_ruter(fylke,linje,bussnummer,bussnavn) VALUES('".$fylke."', '".$linjerMatches[1][$k]."','".$value."', '".$matches[4][$key]."')";
		//$result = mysql_query($sql, $linkID) or die("Error");
	}
}
}

 

My problem is that in each section (tab) all the results appear, from every tab. Like in the tab called Halden the results from Sarpsborg appears as well.

Link to comment
https://forums.phpfreaks.com/topic/187489-parse-bus-plan-please-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.