Php 用于选择IP地址的脚本执行错误
我编写了一个小脚本来从列表中删除不需要的IP地址,但是脚本仍然显示Php 用于选择IP地址的脚本执行错误,php,pdo,Php,Pdo,我编写了一个小脚本来从列表中删除不需要的IP地址,但是脚本仍然显示$IP_list中的IP地址,尽管在条件中,如果什么都没有发生 $ip_list = array("37.13.","217.118.","207.46."); $top = $pdo->prepare('SELECT DISTINCT ip FROM logs ORDER BY ip DESC'); $top->execute(); while ($toppost = $top->fetch(PDO::FETC
$IP_list
中的IP地址,尽管在条件中,如果什么都没有发生
$ip_list = array("37.13.","217.118.","207.46.");
$top = $pdo->prepare('SELECT DISTINCT ip FROM logs ORDER BY ip DESC');
$top->execute();
while ($toppost = $top->fetch(PDO::FETCH_LAZY)){
$array[] = $toppost->ip;
}
for ($i = 0; $i <= count($ip_list); $i++){
for ($a = 0; $a <= count($array); $a++){
$b = explode(".", $array[$a]);
$n = $b[0].".".$b[1].".";
if ($ip_list[$i] == $n){
}
else{
echo $n."<br/>";
}
}
}
$ip_list=数组(“37.13.”、“217.118.”、“207.46”);
$top=$pdo->prepare('SELECTDISTINCT ip FROM logs ORDER BY ip DESC');
$top->execute();
而($toppost=$top->fetch(PDO::fetch_LAZY)){
$array[]=$toppost->ip;
}
对于($i=0;$i请尝试使用unset()
对于($a=0;$a请尝试使用unset()
对于($a=0;$a这应该可以:
PHP
$ip_list = array("37.13.","217.118.","207.46.");
$top = $pdo->prepare('SELECT DISTINCT ip FROM logs ORDER BY ip DESC');
$top->execute();
while ($toppost = $top->fetch(PDO::FETCH_LAZY)){
$b = explode(".", $toppost->ip);
$formated_ip = $b[0].".".$b[1].".";
if (in_array($formated_ip, $ip_list)) {
//IP From database in $ip_list array
} else {
echo $formated_ip . "<br/>";
}
}
$ip_list=数组(“37.13.”、“217.118.”、“207.46”);
$top=$pdo->prepare('SELECTDISTINCT ip FROM logs ORDER BY ip DESC');
$top->execute();
而($toppost=$top->fetch(PDO::fetch_LAZY)){
$b=爆炸(“.”,$toppost->ip);
$formatted_ip=$b[0]。“$b[1]”;
if(在数组中($formatted_ip,$ip_list)){
//$IP_列表数组中来自数据库的IP
}否则{
echo$formatted_ip.“
”;
}
}
这应该可以:
PHP
$ip_list = array("37.13.","217.118.","207.46.");
$top = $pdo->prepare('SELECT DISTINCT ip FROM logs ORDER BY ip DESC');
$top->execute();
while ($toppost = $top->fetch(PDO::FETCH_LAZY)){
$b = explode(".", $toppost->ip);
$formated_ip = $b[0].".".$b[1].".";
if (in_array($formated_ip, $ip_list)) {
//IP From database in $ip_list array
} else {
echo $formated_ip . "<br/>";
}
}
$ip_list=数组(“37.13.”、“217.118.”、“207.46”);
$top=$pdo->prepare('SELECTDISTINCT ip FROM logs ORDER BY ip DESC');
$top->execute();
而($toppost=$top->fetch(PDO::fetch_LAZY)){
$b=爆炸(“.”,$toppost->ip);
$formatted_ip=$b[0]。“$b[1]”;
if(在数组中($formatted_ip,$ip_list)){
//$IP_列表数组中来自数据库的IP
}否则{
echo$formatted_ip.“
”;
}
}
你想做什么?不想要的ip就是你的意思?“在条件中,如果什么都没有发生”,因为你没有代码?负责“删除”的代码在哪里?@MichałSznurawa,也就是说,没有代码,因为我不需要以“37.13.”、“217118.”、“207.46”开头的ip地址。你为什么要装入$array[$a]在使用串联后就将其内爆?你想做什么?不需要的ip意味着什么?“在条件中,如果什么都没有发生”,因为你没有代码?负责“删除”的代码在哪里?@MichałSznurawa,也就是说,没有代码,因为我不需要以“37.13.”、“217118.”、“207.46”开头的ip地址为什么要在使用串联后内插$array[$a]以使其内爆?而且,第一个示例不正确,但第二个完美工作,第一个示例不正确,但第二个完美工作