您好我有这个代码擦除用户输入的页面,如果用户输入的页面编号不是“1000000”,我希望它回显“未找到”我该怎么办?
if (!isset($_POST['submit'])) {
print "<br><br><br>";
echo "<center>";
print "<form action=\"\" method=\"POST\">";
print "<input name=\"dgt\" id=\"hax\" style=\"width:400px\" type=\"text\"> ";
print "<input name=\"submit\" value=\"Decrypt Hash\" type=\"submit\">";
print "</form>";
} else {
$string = file_get_contents('http://www.md5this.com/list.php?page='.$_POST['dgt']);
$regex_pattern = "/<tr>([^`]*?)<\/tr>/";
unset($matches);
preg_match_all($regex_pattern, $string, $matches);
foreach ($matches[0] as $paragraph) {
echo $paragraph;
echo "<br>";
}
}
答案 0 :(得分:0)
然后检查$matches[0]
是否为空。如果没有,请浏览$matches[0]
。如果它是空的,那么echo Not found.
这是最实用的&amp;处理您正在处理的数据的现实方法,因为最终您不知道无效页面是什么,因为其他网站是您无法控制的。
if (!isset($_POST['submit'])) {
print "<br><br><br>";
echo "<center>";
print "<form action=\"\" method=\"POST\">";
print "<input name=\"dgt\" id=\"hax\" style=\"width:400px\" type=\"text\"> ";
print "<input name=\"submit\" value=\"Decrypt Hash\" type=\"submit\">";
print "</form>";
}
else {
$string = file_get_contents('http://www.md5this.com/list.php?page=' . $_POST['dgt']);
$regex_pattern = "/<tr>([^`]*?)<\/tr>/";
unset($matches);
preg_match_all($regex_pattern, $string, $matches);
if(!empty($matches) && !empty($matches[0])) {
foreach ($matches[0] as $paragraph) {
echo $paragraph;
echo "<br>";
}
}
else {
echo 'Not found.';
}
}
答案 1 :(得分:0)
如果我理解正确,这应该有效
if (!isset($_POST['submit'])) {
print "<br><br><br>";
echo "<center>";
print "<form action=\"\" method=\"POST\">";
print "<input name=\"dgt\" id=\"hax\" style=\"width:400px\" type=\"text\"> ";
print "<input name=\"submit\" value=\"Decrypt Hash\" type=\"submit\">";
print "</form>";
} else {
if($_POST['dgt'] < 1000000){
$string = file_get_contents('http://www.md5this.com/list.php?page='.$_POST['dgt']);
$regex_pattern = "/<tr>([^`]*?)<\/tr>/";
unset($matches);
preg_match_all($regex_pattern, $string, $matches);
foreach ($matches[0] as $paragraph) {
echo $paragraph;
echo "<br>";
}
}else{
echo "Not Found";
}
}