VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • php fopen从100万条记录的文本文件取出重复数最多的前10条

fopen函数对于文件的读定操作是专业的并且速度是非常的快了,有时我们没用用到数据库只用到了txt文件了,下面我们来看看fopen从100万条记录的文本文件取出重复数最多的前10条的例子.

100万条记录的文本文件,取出重复数最多的前10条,示例文本:

  1. 098 
  2. 123 
  3. 234 
  4. 789 
  5. …… 
  6. 234 
  7. 678 
  8. 654 
  9. 123 
  10.  
  11. $fp = <a href="/tags.php/fopen/" target="_blank">fopen</a>('文件', 'r'); 
  12.  
  13. while($buf = fgets($fp)) {   $res[$buf]++; 
  14.  
  15. } 
  16.  
  17. fclose($fp); 
  18.  
  19. arsort($res); 
  20.  
  21. $res = array_keys(array_slice($res, 0, 10)); 
  22. //phpfensi.com 
  23. print_r($res); 
  24.  
  25. $a = file('文件'); 
  26.  
  27. $res = array_count_values($a); 
  28.  
  29. arsort($res); 
  30.  
  31. $res = array_keys(array_slice($res, 0, 10)); 
  32.  
  33. print_r($res);
  34.  

出处:http://www.phpfensi.com/php/20150509/9988.html


相关教程