我剛剛進入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