-3

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";
 ...
ror
  • 11
  • 3
  • What's the actual problem you are trying to solve? And what does this really have to do with rails, internationalization or translation? A far simpler solution may be just to use text editor which allows you to do search and replace on all files in a folder. – max Aug 03 '15 at 01:02
  • the site is actually written in php and it's for translation purpose. What I want to do is actually finding all of the code that got translation in it. Got nothing to do with rails, it's just I am more convinient with ruby so I prefer it in ruby. thanks – ror Aug 03 '15 at 01:18
  • http://stackoverflow.com/questions/3873857/php-to-ruby-compiler – bjhaid Aug 03 '15 at 02:28
  • i got lots of php file in which i need to find some code that contain translation on it. got nothing to do with ruby. this is a pure php files. i just need to get those code using ruby thats all. – ror Aug 03 '15 at 03:56

1 Answers1

1

You can just use grep for it:

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

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
EugZol
  • 6,476
  • 22
  • 41