如何在dom php html find中使用elseif语句
如何添加语句,当我搜索时,它在url上不存在,它将显示nothing.html如何在dom php html find中使用elseif语句,php,html,Php,Html,如何添加语句,当我搜索时,它在url上不存在,它将显示nothing.html $url1 = "http://www.pengadaan.net/tend_src_cont2.php?src_nm="; $url2 = $_GET['src_nm']."&src_prop="; $url3 = $_GET['src_prop']; $url = $url1.$url2.$url3; $html = file_get_html($url); if
$url1 = "http://www.pengadaan.net/tend_src_cont2.php?src_nm=";
$url2 = $_GET['src_nm']."&src_prop=";
$url3 = $_GET['src_prop'];
$url = $url1.$url2.$url3;
$html = file_get_html($url);
if (method_exists($html,"find")) {
echo "<ul>";
foreach($html->find('div[class=pengadaan-item] h1[] a[]') as $element ) {
echo ("<li>".$element."</li>");
}
echo "</ul>";
echo $url;
}
else {
}
$url1=”http://www.pengadaan.net/tend_src_cont2.php?src_nm=";
$url2=$\u GET['src\u nm']。“&src\u prop=“;
$url3=$\u GET['src\u prop'];
$url=$url1.$url2.$url3;
$html=file\u get\u html($url);
如果(方法_存在($html,“find”){
回声“”;
foreach($html->find('div[class=pengadaan item]h1[]a[])作为$element){
回声(“- ”$element.“
”);
}
回声“
”;
echo$url;
}
否则{
}
在PHP中,有两种方法可以移动到另一个页面。您可以执行标题(“位置:http://www.yourwebsite.com/nothing.php");
或者您可以使用PHPecho
JavaScript执行reidrect(如果您已经定义了标题):
或者,如果您已经发送了标题,您可以使用JavaScript绕过它:
...
} else {
echo '<script>window.location.replace("http://www.pengadaan.net/nothing.php")</script>';
}
。。。
}否则{
“echo”窗口。位置。替换(“http://www.pengadaan.net/nothing.php")';
}
就是这样:你能帮我解决这个问题吗@泽克姆西并不真正理解这个问题。您想知道如何添加elseif
语句吗?让它做什么?不,我的意思是,我想知道条件,如果,如果find(…)==null,它将不显示任何内容。你能帮我@SpencerWieczorek吗?你想回显文本nothing.html
,还是转到nothing.html
?先生,我能给你发一封我的文件的电子邮件吗。我要你检查一下。你就会知道这是什么意思@阿尔芬汉德拉是我上面说的不是你想要的?我认为没有必要将您的文件发送给我(您的代码片段很好)。是否存在执行关键字匹配的方法\u
?还是你没做?对不起,先生,我这里有点困惑,英语不好。我正在抓取。并从当地主持人那里展示。先生?@Alfinancehandra好的,如果您的网站不是“www.pengadan.net”,那么就使用URI/nothing.php
。@Alfinancehandra在第二个示例上加了一个分号。你犯了什么错误?
...
} else {
echo '<script>window.location.replace("http://www.pengadaan.net/nothing.php")</script>';
}