大家好,我有这段代码:
<?php
include './simple_html_dom.php';
//this link exists
$teste = new simple_html_dom("http://www.btolinux.com.br/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
$teste->find("html");
}
//At this time I'm forcing get a 404 error link.
$teste = new simple_html_dom("http://www.btolinux.com.br/error/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
$teste->find("html");
}
//Now I'm get the correct link again. Why the error persists?
$teste = new simple_html_dom("http://www.btolinux.com.br/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
$teste->find("html");
}
?>
因此,在我的代码中,当我找到404错误链接时,在使用同一类创建的下一个对象中,错误仍然存在。我怎么解决这个问题?
要尝试此代码,请在http://sourceforge.net/projects/simplehtmldom/files/中获取Simple_dom_php
尝试@以避免警告,如下所示:
<?php
//CORRECT
$url = "http://www.btolinux.com.br/";
$html = @file_get_contents($url);
if ($html!='') {
$teste = new simple_html_dom($url);
echo 'SIZE: '.$teste->original_size."<br>";
}
//ERROR
$url = "http://www.btolinux.com.br/error/";
$html = @file_get_contents($url);
if ($html!='') {
$teste = new simple_html_dom($url);
echo 'SIZE: '.$teste->original_size."<br>";
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句