3

I'm trying to come up with a solution to this problem. I have a Ruby script that needs to run some PHP code, but I am new to Ruby, so I don't know how to go about doing this.

def run_my_code
    #execute some PHP code here
    # $person = new Person();
    # $person->doSomething();
end

How can I achieve this?

Andrew
  • 212,236
  • 189
  • 499
  • 691
  • Related question: [PHP to Ruby compiler](http://stackoverflow.com/questions/3873857/php-to-ruby-compiler/3886423#3886423) – Andrew Grimm Oct 17 '10 at 06:14
  • Possible duplicate of [PHP to Ruby compiler](https://stackoverflow.com/questions/3873857/php-to-ruby-compiler) – mega6382 Nov 10 '17 at 06:49

3 Answers3

5

one way is to use exec

http://ruby-doc.org/core/classes/Kernel.html#M005968

also `ls` or `cmd` works too (back tick)

nonopolarity
  • 139,253
  • 125
  • 438
  • 698
3

I've heard of Phuby, though I haven't used it myself.

Andrew Grimm
  • 74,534
  • 52
  • 194
  • 322
2

Look at Erubis. It supports PHP and other languages (Ruby/PHP/C/Java/Scheme/Perl/Javascript).

NARKOZ
  • 26,001
  • 7
  • 65
  • 89