Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...