Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

how to pull out php code that contain certain words in ruby

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 "

{$this->te('Attachments')}:
";
 ...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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("
").each_with_index do |line, n|
    puts "Found at #{x}:#{n+1}" if line["$this->te"]
  end
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...