源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP简单实现遍历目录下特定文件的方法小结

  • 时间:2022-01-24 16:30 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP简单实现遍历目录下特定文件的方法小结
本文实例讲述了PHP简单实现遍历目录下特定文件的方法。分享给大家供大家参考,具体如下: [b]1. 使用glob方法[/b]
foreach (glob("modules/*.php") as $filename) {
  echo $filename;
}

[b]2. 利用Linux下的ls命令[/b]
function iterator($pattern, $__FILE__) {
 preg_match("/^(.+)\/[^\/]+$/", $__FILE__, $matches);
 $ls = `ls $matches[1]/$pattern`;
 $ls = explode("\n", $ls);
 array_pop($ls); // remove empty line ls always prints
 foreach ($ls as $inc) {
  echo($inc);
 }
}
iterator("modules/*.php",__FILE__);
更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/420.htm]PHP目录操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/59.htm]php文件操作总结[/url]》、《[url=http://www.1sucai.cn/Special/242.htm]PHP常用遍历算法与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/614.htm]PHP数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/111.htm]php程序设计算法总结[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部