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
  • 227,796
  • 193
  • 515
  • 708
  • 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
  • 146,324
  • 131
  • 460
  • 740
3

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

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
2

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

NARKOZ
  • 27,203
  • 7
  • 68
  • 90