php 文件中随机取出一条数据

  1. <?php 
  2. //第一种方法: 
  3. $line = getrandline1('test.txt'); 
  4. function getrandline1($filename
  5.  $linenum = 0; 
  6.  $fh = fopen($filename'r'); 
  7.  while(!feof($fh)) 
  8.  { 
  9.   if($rowcontents = fgets($fh)) 
  10.   { 
  11.    $linenum++; 
  12.    $contens[] = $rowcontents
  13.   } 
  14.  } 
  15.  $randline = mt_rand(0, $linenum – 1); 
  16.  $line = $contens[$randline]; 
  17.  fclose($fh); 
  18.  return $line
  19.   
  20. //第二种方法: 
  21. $line = getrandline2('test.txt'); 
  22. function getrandline2($filename
  23.  $contents = file('test.txt'); 
  24.  $linenum = count($contents); 
  25.  $randline = mt_rand(0, $linenum – 1); 
  26.  $line = $contents[$randline]; 
  27.  return $line
  28.   
  29. //第三种方法: 
  30. $line = getrandline3('test.txt'); 
  31. function getrandline3($filename
  32.  $contents = file('test.txt'); 
  33.  shuffle($contents); 
  34.  return $contents[0]; 
  35.   
  36. //第四种方法: 
  37. $line = getrandline4('test.txt'); 
  38. function getrandline4($filename
  39.  $linenum = 0; 
  40.  $fh = fopen($filename'r'); 
  41.  while(!feof($fh)) 
  42.  { 
  43.   if($linecontents = fgets($fh)) 
  44.   { 
  45.    $linenum++; 
  46.                         $randint = (mt_rand(1, 1000000 * $linenum) – 1)/1000000); 
  47.    if($randint < 1) 
  48.    { 
  49.     $line = $linecontents
  50.    } 
  51.   } 
  52.  } 
  53.  fclose($fh); 
  54.  return $line
  55. ?> 
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » php 文件中随机取出一条数据

132 评论

  1. buy spironolactone online cheap valtrex 1000mg us buy diflucan 200mg without prescription

  2. buy salbutamol 100mcg for sale sildenafil pills cheap sildenafil pills

  3. order tadalafil 10mg online cheap Cialis generic real viagra pills

  4. buy generic cialis 10mg anafranil cost anafranil over the counter

  5. order orlistat without prescription cost acyclovir 800mg order acyclovir 800mg generic

  6. buy generic pepcid 20mg pepcid tablet order remeron 30mg sale

  7. order requip 1mg without prescription ropinirole for sale buy labetalol 100 mg pills

  8. cost esomeprazole generic biaxin purchase furosemide for sale

  9. buy cialis 40mg without prescription approved levitra medication for ed

  10. provigil 200mg drug zestril 5mg drug purchase metoprolol for sale

  11. best viagra sites online price viagra cialis from canada

  12. difference between omeprazole and omeprazole delayed release prilosec for babies omeprazole prices

  13. difference between prozac and fluoxetine prozac 10mg stopping prozac suddenly

  14. cephalexin dosage for dogs urinary tract infection cephalexin antibiotics can cephalexin be given to dogs

  15. can i have a glass of wine while on ciprofloxacin ciprofloxacin 500mg can you take ciprofloxacin for a tooth infection

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡