我刚刚进入PHP编程,并在我的for
循环中出现错误。当我把它剪掉时,代码运行良好。for循环中的错误?
<?php
// Utils
function contains($needle, $haystack) {
return strpos($haystack, $needle) !== false;
}
$client_ip = $_SERVER['REMOTE_ADDR'];
$iphitsfile = fopen("iphits.txt","r");
$iphits = fgets($iphitsfile,1000);
fclose($iphitsfile);
echo $iphits;
$ips = split(" ", $iphits);
for($ip_and_hits : $ips) {
echo "$ip_and_hits";
$ip = split("-", $ip_and_hits);
$hits = split("-", $ip_and_hits);
if($ip == $client_ip) {
$hits = $hits + 1;
$iphits = str_replace($ip_and_hits,$ip."-".$hits." ",$iphits);
$iphitsfile = fopen("iphits.txt","w");
fwrite($iphitsfile, $iphits);
fclose($iphitsfile);
break;
}
}
?>
不要辱骂,让过去我们的质量过滤器。参加[旅游]并访问[问],了解我们对这里帖子的期望。 – rene