PHP 和正则表达式在目录中查找文件然后运行正则表达式
在不同目录中查找文本文件然后对这些找到的文件运行正则表达式的最有效方法是什么。我将在本地运行 php/scripts。
假设我有 D:\Script\ 我想从中运行脚本,还有 D:\Script\folder_01、D:\Script\folder_02 等,我希望该脚本从中查看文件。这些文件夹名称不符合逻辑,它们可以是任何名称。
因此,我不想找到每个文件,而只想找到包含以下行的文件:“游戏类型:xxxxx”。 (匹配的文本文件数量约为 150-200),
找到这些文件后,我想一次运行一些 preg_replace 一个文件。
谢谢。
what's the the most efficient way to find text files in different directories and then run regex to those found files. I will run php/scripts locally.
Let's say I have D:\Script\ where i want to run my script from and D:\Script\folder_01, D:\Script\folder_02, etc. where i want that script to look the files from. Those folder names aren't logical, they could be anything.
So, i don't want to find every files but only the files that contains the line: "Game type: xxxxx". (matching number of text files would be around 150-200)
And after finding those files, I'd like to run some preg_replace one file at a time.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要在本地运行此程序,其他语言可能会更快或更容易实现。
不过,如果您想使用 PHP 来实现此目的:
如果您不需要找到某个字符串的所有文件的列表,则可以将步骤 3 和 4 合并为一个。
在代码中:
If you're going to run this locally, other languages are probably faster and or easier to implement.
Nevertheless, if you want to use PHP for this:
Steps 3 and 4 can be folded into one if you don't need a list of all the files where you find a certain string.
In code:
这能完成全部任务吗?或者我错过了一些重要的事情?
抱歉我是新手! :)
Will this do the whole trick? Or am I missing something crucial?
Sorry i'm a newbie! :)