本文實例講述了PHP讀取文本文件并逐行輸出該行使用最多的字符與對應次數的方法。分享給大家供大家參考,具體如下:
test.txt文件:
Welcome to our website vevb.comm.survivalescaperooms.comphp asp java jsp
php代碼(讀取test.txt文件):
$myfile = fopen("test.txt", "r");while(!feof($myfile)) { $line_str = fgets($myfile); $str_arr = count_chars($line_str, 1); arsort($str_arr); print_r(chr(key($str_arr)).' is '.current($str_arr).PHP_EOL);}fclose($myfile);運行結果如下:
e is 5 w is 3 p is 4
希望本文所述對大家PHP程序設計有所幫助。
新聞熱點
疑難解答
圖片精選