Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ruby中提取包含特定单词的php代码_Php_Ruby On Rails_Ruby_Internationalization_Translation - Fatal编程技术网

如何在ruby中提取包含特定单词的php代码

如何在ruby中提取包含特定单词的php代码,php,ruby-on-rails,ruby,internationalization,translation,Php,Ruby On Rails,Ruby,Internationalization,Translation,假设我有很多php文件(.php),我只想取出包含某些单词的代码块,例如$this->te 知道我怎么做吗?使用ruby会更好吗 if ($attachments && count($attachments) > 0) { echo "\n\n{$this->te('Attachments')}:\n"; ... 您只需使用grep即可: grep '$this->te' -R *.php -n 如果您想用Ruby做类似的事情,可以使用以下方法: Dir

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

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

您只需使用
grep
即可:

grep '$this->te' -R *.php -n
如果您想用Ruby做类似的事情,可以使用以下方法:

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

你想解决的实际问题是什么?这与rails、国际化或翻译有什么关系?一个简单得多的解决方案可能只是使用文本编辑器,它允许您搜索和替换文件夹中的所有文件。该网站实际上是用php编写的,用于翻译目的。我想做的是找到所有包含翻译的代码。与rails无关,只是我对ruby更方便,所以我更喜欢ruby。thanksi有很多php文件,我需要在其中找到一些包含翻译的代码。与鲁比无关。这是一个纯php文件。我只需要使用ruby来获取这些代码,仅此而已。