2

I need to go through in each and every folders/files in php to find some specific keyword in this case translation format e.g $this-> and $translator->.

I need to get those result and put it on to new files.

Here is what I have tried before using ruby.

this = File.readlines("folder_path.php")
#If I need to get any translation that contain $this-> should I use grep? I tried using grep before but not giving result that I need.

that = File.open("new_file.txt", "w")
that << this 
that.close

Hope that I didn't make any confusion. Thanks.

  • You need to do this in PHP? Why is this a Ruby question? You don't say what OS you're on, but if you're on *nix, I'd strongly suggest using `grep` or one of its siblings. It's going to be faster than anything you can write in Ruby. – the Tin Man Aug 07 '15 at 01:01
  • Got an assignment and it's written in php. I don't know much about php so ruby is my option. What it got to do with OS @theTinMan? when u say *nix, what do u mean by that? any suggestion? thanks – user5200113 Aug 07 '15 at 01:14
  • https://en.wikipedia.org/wiki/Unix-like – the Tin Man Aug 07 '15 at 01:18
  • @theTinMan good to know that. Well i am a new to this term, i guess you must be a pro.. got what I need. Thanks anyway – user5200113 Aug 07 '15 at 03:06

1 Answers1

0

Just use grep:

grep '$this->' -R *.php -n > result.txt
EugZol
  • 6,476
  • 22
  • 41
  • 1
    And actually, that's a duplicate of: http://stackoverflow.com/questions/31777853/how-to-pull-out-php-code-that-contain-certain-words-in-ruby/31781864#31781864 Are you guys working together or something? :) – EugZol Aug 07 '15 at 00:07
  • Hi @EugZol, I am getting this error `ex.rb:1: syntax error, unexpected *, expecting keyword_do or '{' or '(' grep '$this->' -R *.php -n > result.txt ^` – user5200113 Aug 07 '15 at 00:11
  • 1
    @user5200113 This is terminal command :) Not a Ruby script. Just run in in bash console. – EugZol Aug 07 '15 at 00:12
  • @user5200113 You are welcome! Accept my answer then (you should press 'V'-shaped mark near it) :) – EugZol Aug 07 '15 at 08:12
  • I got another question, the command only print out those line. If that's on a different line/new line, I am not getting the whole syntax. e.g. >
    placeholder="test">New User >
    If I want to get the whole syntax, is it possible? and also where can i find some tutorial on command line(not so basic one)? I know basic bash command and most online tutorial that I found only touch basic stuff. if you could direct me that would be appreciated. Thanks @EugZol
    – user5200113 Aug 10 '15 at 05:21
  • It's better to post another question, you can provide link here if you want me to look at it. – EugZol Aug 10 '15 at 15:54