如何拉出包含某些单词在Ruby中的php代码 [英] how to pull out php code that contain certain words in ruby

查看:78
本文介绍了如何拉出包含某些单词在Ruby中的php代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有很多php文件(.php),而我只想提取包含某些单词的代码块,例如$ this-> te 知道我该怎么做吗?使用红宝石会更好?

Say if i have lots of php file (.php) and I'm only want to pull out block of code that contain certain words e.g. $this->te Any idea how I do it? using ruby would be better?

if ($attachments && count($attachments) > 0) {
 echo "\n\n{$this->te('Attachments')}:\n";
 ...

推荐答案

您可以直接使用grep:

grep '$this->te' -R *.php -n

如果您想对Ruby做类似的事情,可以使用类似的东西:

If you want to do similar thing with Ruby, you can use something like:

Dir.glob('*.php').each do |x|
  File.read(x).split("\n").each_with_index do |line, n|
    puts "Found at #{x}:#{n+1}" if line["$this->te"]
  end
end

这篇关于如何拉出包含某些单词在Ruby中的php代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆