Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 选择<;表>;预赛_Php_Html_Regex_Parsing - Fatal编程技术网

Php 选择<;表>;预赛

Php 选择<;表>;预赛,php,html,regex,parsing,Php,Html,Regex,Parsing,我在解析来自另一个网站的数据时遇到了一些困难。我可以从中获得第一次平静,但是当我试图从第一次切割中取出剩余的部分时,事情就停止了。代码如下: $html = file_get_contents("http://www.avto.net/_DEALER/results.asp?broker=12430&star=&izpis=1&oglasrubrika=7&oblika=0&subKAT=0&model="); $pattern = '/&l

我在解析来自另一个网站的数据时遇到了一些困难。我可以从中获得第一次平静,但是当我试图从第一次切割中取出剩余的部分时,事情就停止了。代码如下:

$html = file_get_contents("http://www.avto.net/_DEALER/results.asp?broker=12430&star=&izpis=1&oglasrubrika=7&oblika=0&subKAT=0&model="); 

 $pattern = '/<div class=\"contentwrapper\">(.*?)<\/div>/s'; 

preg_match($pattern, $html, $data); 
$form = '/<form.*?>(.*?)<\/form>/s'; 
preg_match($form, $data[1], $cut); 

$pattern2 ='/<table width="730" cellspacing="0" cellpadding="0" border="0">(.*?)<\/table>/s'; 

preg_match_all($pattern2, $cut[1], $tabele); 

echo "<pre>"; 
print_r($cut[0]); 
echo "</pre>"; 

echo "<br />"; 
echo "<br />"; 

echo "<pre>"; 
print_r($tabele); 
echo "</pre>";  
$html=文件获取内容(“http://www.avto.net/_DEALER/results.asp?broker=12430&star=&izpis=1&oglasrubrika=7&oblika=0&subKAT=0&model="); 
$pattern='/(**?)/s';
预匹配($pattern,$html,$data);
$form='/(.*)/s';
预匹配($form,$data[1],$cut);
$pattern2='/(.*?)/s';
preg_match_all($pattern2,$cut[1],$tabele);
回声“;
打印($cut[0]);
回声“;
回声“
”; 回声“
”; 回声“; 打印(tabele); 回声“;
我需要contentwrapper类,但我必须稍微清理一下,这样它将只显示包含汽车部件的表,而不需要额外的文本或页码。第一个preg_匹配运行良好,但是当尝试获取所有这些表->(*)时,结果是没有。欢迎任何提示。我也尝试过使用“Simple HTML DOM parser”,它有函数文件_get_HTML(),但我需要的是,我只需要从第一页(不是全部30页)获取项目列表,然后将它们显示在我的页面上


任何帮助/提示都将不胜感激

首先,不要使用正则表达式解析html

最后但并非最不重要的一点是,使用DOM和

示例:



我同意下面的答案,不使用正则表达式,但如果您仍然需要正则表达式来匹配表标记:
$pattern2='/\(.*)\/is'是否有一种方法可以使每个结果在数组中都有自己的位置?有了这个,一切都转到$array[0],我想把它们放在$array[0][0],$array[0][1]?
<?php

$html_text = "your html code goes here...";

$d = new DOMDocument();
@$d->loadHTML($html_text);
$xpath = new DOMXPath($d);
$result = $xpath->query("//table");

foreach ($result as $table)
{
    echo $table->textContent;

}

?>