好日子亲爱的社区!如何使用PHP解析一个非常简单的表格
我需要构建一个函数来解析一个非常简单的表 (带有一些标签和值)的内容,请参阅下面的URL。我已经使用各种方式来解析html源代码。但这一个是有点棘手!见我需要解析的目标 - 它有一些invaild标记:
目标:http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=644.0013008534253&SchulAdresseMapDO=194190
嗯,我这一个
<?php
require_once('config.php'); // call config.php for db connection
$filename = "url.txt"; // Include the txt file which have urls
$each_line = file($filename);
foreach($each_line as $line_num => $line)
{
$line = trim($line);
$content = file_get_contents($line);
//echo ($content)."<br>";
$pattern = '/<td>(.*?)<\/td>/si';
preg_match_all($pattern,$content,$matches);
foreach ($matches[1] as $match) {
$match = strip_tags($match);
$match = trim($match);
//var_dump($match);
$sql = mysqli_query("insert into tablename(contents) values ('$match')");
//echo $match;
}
}
?>
好试了一下 - 见正则表达式在线7-11:它不匹配!我不得不重做这个脚本的解析器部分。我需要解析一些不同的东西 - 因为parsercode不完全符合目标。它旨在取回表格的结果。
任何人都可以帮助我在这里得到一个更好的正则表达式 - 或更好的方式来解析这个网站... 任何和所有的帮助将大大apprecaited。
问候 零
做TD的有属性或其他sruff?怎么样一个XML解析器? – 2010-12-19 11:08:26
''无法在您要解析的网页中显示。 – 2010-12-19 11:08:36
看看http://simplehtmldom.sourceforge.net/(为了您的html解析需要) – Andreas 2010-12-19 11:10:42