我想計算文本文件中的單詞數。下面是我嘗試過的代碼。php 代碼工作正常,但它也計算空白。我應該添加什么才能使代碼不計算空格。我的PHP代碼:<?php $count = 0; //Opens a file in read mode $file = fopen("trial.txt", "r"); //Gets each line till end of file is reached while (($line = fgets($file)) !== false) { //Splits each line into words $words = explode(" ", $line); //Counts each word $count = $count + count($words); } print("Number of words : " . $count); fclose($file);?>
PHP計算txt文件中的單詞
慕的地6264312
2022-10-28 16:16:56