Help with php table scraping

Hi guys!

Its my first post on the site so bear with me :slight_smile:

Ok so i’m a complete beginner with PHP and I have a specific need for it for my project. I’m hoping some of you guys could help!

Basically, I want to scrape a webpage and access a certain html table and its information. I need to parse out this info and simply format it in a desired result.

So where to begin… heres my php I have written so far

[php]

<?php $url = "http://www.goldenplec.com/festivals/oxegen-2/oxegen-2011"; $raw = file_get_contents($url); $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B"); $content = str_replace($newlines, "", html_entity_decode($raw)); $start = strpos($content,'<table style="background: #FFF; font-size: 13px;"'); $end = strpos($content,'',$start) + 8; $table = substr($content,$start,$end-$start); echo $table; /* Regex here to echo the desired result */ ?>

[/php]

That URL contains the table I need. My code will simply echo that exact table.

However, and heres my problem, I’m by no means a reg-ex expert and I need to display the data from the table in a certain format. I want to echo an xml file containing a number of sql insert statements as follows:

[php]
$xml_output .= “INSERT INTO timetable VALUES(1,‘Black Eyed Peas’,‘Main Stage’,‘Friday’, ‘23:15’)”;
$xml_output .= “INSERT INTO timetable VALUES(2,‘Swedish House Mafia’,‘Vodafone Stage’,‘Friday’, ‘23:30’)”;
$xml_output .= “INSERT INTO timetable VALUES(3,‘Foo Fighters’,‘Main Stage’,‘Saturday’, ‘23:25’)”;
$xml_output .= “INSERT INTO timetable VALUES(4,‘Deadmau5’,‘Vodafone Stage’,‘Saturday’, ‘23:05’)”;
$xml_output .= “INSERT INTO timetable VALUES(5,‘Coldplay’,‘Main Stage’,‘Sunday’, ‘22:25’)”;
$xml_output .= “INSERT INTO timetable VALUES(6,‘Pendalum’,‘Vodafone Stage’,‘Sunday’, ‘22:15’)”;
[/php]

I hope I have provided enough info and I would greatly appreciate any help from you kind folk.

Thanks in advance,

Karl

Sponsor our Newsletter | Privacy Policy | Terms of Service