这是我在网站上的第一篇文章,所以请多多包涵
好的,所以我是 PHP 的完整初学者,我的项目对它有特定的需求。我希望你们中的一些人可以提供帮助!
基本上,我想抓取一个网页并访问某个 html 表及其信息。我需要解析出这些信息并简单地将其格式化为所需的结果。
那么从哪里开始.....继承人我到目前为止写的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,'</table>',$start) + 8;
$table = substr($content,$start,$end-$start);
echo $table;
/* Regex here to echo the desired result */
?>
该 URL 包含我需要的表。我的代码将简单地回显那个确切的表格。
但是,这是我的问题,我绝不是 reg-ex 专家,我需要以某种格式显示表格中的数据。我想回显一个包含许多 sql 插入语句的 xml 文件,如下所示:
$xml_output .= "<statement>INSERT INTO timetable VALUES(1,'Black Eyed Peas','Main Stage','Friday', '23:15')</statement>";
$xml_output .= "<statement>INSERT INTO timetable VALUES(2,'Swedish House Mafia','Vodafone Stage','Friday', '23:30')</statement>";
$xml_output .= "<statement>INSERT INTO timetable VALUES(3,'Foo Fighters','Main Stage','Saturday', '23:25')</statement>";
$xml_output .= "<statement>INSERT INTO timetable VALUES(4,'Deadmau5','Vodafone Stage','Saturday', '23:05')</statement>";
$xml_output .= "<statement>INSERT INTO timetable VALUES(5,'Coldplay','Main Stage','Sunday', '22:25')</statement>";
$xml_output .= "<statement>INSERT INTO timetable VALUES(6,'Pendalum','Vodafone Stage','Sunday', '22:15')</statement>";
我希望我已经提供了足够的信息,我将非常感谢你们善良的人们的任何帮助。
提前致谢。