首页 > 语言 > PHP > 正文

PHP读取文本文件并逐行输出该行使用最多的字符与对应次数的方法

2024-05-04 23:52:53
字体:
来源:转载
供稿:网友

本文实例讲述了PHP读取文本文件并逐行输出该行使用最多的字符与对应次数的方法。分享给大家供大家参考,具体如下:

test.txt文件:

Welcome to our website vevb.comwww.vevb.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程序设计有所帮助。


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选