# Ruby and PHP code in html-page

**URL:** https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035
**Category:** ruby-talk
**Created:** [12 July 2007 13:12 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035 "2007-07-12T13:12:34Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Vadim\_Shevchenko](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vadim\_Shevchenko](https://rubytalk.org/u/Vadim_Shevchenko)
#### Post date: [12 July 2007 13:12 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/1 "2007-07-12T13:12:34Z")

</div>

For example I have such html-page:

test.html

> **···**
>
> ==========
> 
> \<html\>  
> &nbsp;&nbsp;\<body\>  
> &nbsp;&nbsp;\<%  
> &nbsp;&nbsp;puts 'hello'  
> &nbsp;&nbsp;%\>
> 
> &nbsp;&nbsp;\<hr\>
> 
> &nbsp;&nbsp;\<?php
> 
> &nbsp;&nbsp;phpinfo();
> 
> &nbsp;&nbsp;?\>  
> &nbsp;&nbsp;\</body\>  
> \</html\>
> 
> ===========
> 
> Main web-server script-language is Ruby.  
> I want to include PHP-code.
> 
> Is it posiible?
> 
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

### Author: ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)
#### Post date: [12 July 2007 14:23 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/2 "2007-07-12T14:23:29Z")

</div>

It is possible if you run the code first through ERB and then through  
PHP or vice versa.

How slow it will be depends on your deployment type - i.e. whether do  
you run PHP and/or Ruby as CGI, mod\_ruby, using mongrel etc.

If mod\_php allows you to define a post\_request filter, that might  
help. Or you could create a subrequest to php, and than process its  
output.

I see a maintainability problem here - two languages intermixed.  
The easier way would be to separate all the php or ruby stuff to a  
separate webservice/subpage, and include its output to the main page.

...and if you want to really inter-mix ruby and php, that would be a  
nightmare 😉  
as in:

\<% 1..2.each do |i| %\>  
\<?php

?\>  
\<% end %\>

J.

> **···**
>
> On 7/12/07, Vadim Shevchenko \<veejar.net@gmail.com\> wrote:
> 
> > For example I have such html-page:
> > 
> > # test.html
> > 
> > \<html\>  
> > &nbsp;&nbsp;\<body\>  
> > &nbsp;&nbsp;\<%  
> > &nbsp;&nbsp;puts 'hello'  
> > &nbsp;&nbsp;%\>
> > 
> > &nbsp;&nbsp;\<hr\>
> > 
> > &nbsp;&nbsp;\<?php
> > 
> > &nbsp;&nbsp;phpinfo();
> > 
> > &nbsp;&nbsp;?\>  
> > &nbsp;&nbsp;\</body\>  
> > \</html\>
> > 
> > ===========
> > 
> > Main web-server script-language is Ruby.  
> > I want to include PHP-code.
> > 
> > Is it posiible?

---

<div class="post-metadata">

### Author: ![Wayne\_E\_Seguin](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@Wayne\_E\_Seguin](https://rubytalk.org/u/Wayne_E_Seguin)
#### Post date: [15 July 2007 11:48 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/3 "2007-07-15T11:48:12Z")

</div>

Try using SSI for the php code.

> **···**
>
> On Jul 12, 2007, at 09:12 , Vadim Shevchenko wrote:
> 
> > For example I have such html-page:
> > 
> > # test.html
> > 
> > \<html\>  
> > &nbsp;&nbsp;\<body\>  
> > &nbsp;&nbsp;\<%  
> > &nbsp;&nbsp;puts 'hello'  
> > &nbsp;&nbsp;%\>
> > 
> > &nbsp;&nbsp;\<hr\>
> > 
> > &nbsp;&nbsp;\<?php
> > 
> > &nbsp;&nbsp;phpinfo();
> > 
> > &nbsp;&nbsp;?\>  
> > &nbsp;&nbsp;\</body\>  
> > \</html\>
> > 
> > ===========
> > 
> > Main web-server script-language is Ruby.  
> > I want to include PHP-code.
> > 
> > Is it posiible?
> 
> --  
> Wayne E. Seguin  
> Sr. Systems Architect & Systems Admin  
> wayneseguin@gmail.com

---

<div class="post-metadata">

### Author: ![James\_Britt](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@James\_Britt](https://rubytalk.org/u/James_Britt)
#### Post date: [12 July 2007 17:54 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/4 "2007-07-12T17:54:55Z")

</div>

I've been thinking about this as well lately.  
Since Rails is overkill for a lot of little things, it would be nice if ERb had more ability.  
ERb lacks some of the functionality and flexibility of embedded php.  
With php you can just include a file, but ERb doesn't let you do that (AFAIK).

John Joyce

> **···**
>
> On Jul 12, 2007, at 9:23 AM, Jano Svitok wrote:
> 
> > On 7/12/07, Vadim Shevchenko \<veejar.net@gmail.com\> wrote:
> > 
> > > For example I have such html-page:
> > > 
> > > # test.html
> > > 
> > > \<html\>  
> > > &nbsp;&nbsp;\<body\>  
> > > &nbsp;&nbsp;\<%  
> > > &nbsp;&nbsp;puts 'hello'  
> > > &nbsp;&nbsp;%\>
> > > 
> > > &nbsp;&nbsp;\<hr\>
> > > 
> > > &nbsp;&nbsp;\<?php
> > > 
> > > &nbsp;&nbsp;phpinfo();
> > > 
> > > &nbsp;&nbsp;?\>  
> > > &nbsp;&nbsp;\</body\>  
> > > \</html\>
> > > 
> > > ===========
> > > 
> > > Main web-server script-language is Ruby.  
> > > I want to include PHP-code.
> > > 
> > > Is it posiible?
> > 
> > It is possible if you run the code first through ERB and then through  
> > PHP or vice versa.
> > 
> > How slow it will be depends on your deployment type - i.e. whether do  
> > you run PHP and/or Ruby as CGI, mod\_ruby, using mongrel etc.
> > 
> > If mod\_php allows you to define a post\_request filter, that might  
> > help. Or you could create a subrequest to php, and than process its  
> > output.
> > 
> > I see a maintainability problem here - two languages intermixed.  
> > The easier way would be to separate all the php or ruby stuff to a  
> > separate webservice/subpage, and include its output to the main page.
> > 
> > ...and if you want to really inter-mix ruby and php, that would be a  
> > nightmare 😉  
> > as in:
> > 
> > \<% 1..2.each do |i| %\>  
> > \<?php
> > 
> > ?\>  
> > \<% end %\>
> > 
> > J.

---

<div class="post-metadata">

### Author: ![Vadim\_Shevchenko](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vadim\_Shevchenko](https://rubytalk.org/u/Vadim_Shevchenko)
#### Post date: [30 July 2007 12:48 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/5 "2007-07-30T12:48:38Z")

</div>

Wayne E. Seguin wrote:

> > ===========
> > 
> > Main web-server script-language is Ruby.  
> > I want to include PHP-code.
> > 
> > Is it posiible?
> 
> Try using SSI for the php code.

SSI works super, but I have such problem:  
I want to include in html-file some php-code one of counter-systems  
written on PHP.  
By using SSI, I must write php-code to some php-file and when this php  
will be included, php-script don't know about html-file, about first  
request uri.  
For counter-system it's bad variant.

> **···**
>
> > On Jul 12, 2007, at 09:12 , Vadim Shevchenko wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![James\_Britt3](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@James\_Britt3](https://rubytalk.org/u/James_Britt3)
#### Post date: [12 July 2007 18:28 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/6 "2007-07-12T18:28:16Z")

</div>

John Joyce wrote:

> I've been thinking about this as well lately.  
> Since Rails is overkill for a lot of little things, it would be nice if ERb had more ability.

Look at Ramaze or Nitro. Or IOWA or Cerise. Or Merb. Or Camping.

Or roll your own.

Rule your world.

> **···**
>
> --  
> James Britt
> 
> [http://www.rubyaz.org](http://www.rubyaz.org) - Hacking in the Desert  
> [http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys

---

<div class="post-metadata">

### Author: ![Jeremy\_Henty1](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Jeremy\_Henty1](https://rubytalk.org/u/Jeremy_Henty1)
#### Post date: [12 July 2007 18:45 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/7 "2007-07-12T18:45:02Z")

</div>

\<%= IO.read "yes\_it\_does.txt" %\>

Jeremy Henty

> **···**
>
> On 2007-07-12, John Joyce \<dangerwillrobinsondanger@gmail.com\> wrote:
> 
> > With php you can just include a file, but ERb doesn't let you do  
> > that (AFAIK).

---

<div class="post-metadata">

### Author: ![Travis\_D\_Warlick\_Jr](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@Travis\_D\_Warlick\_Jr](https://rubytalk.org/u/Travis_D_Warlick_Jr)
#### Post date: [12 July 2007 22:46 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/8 "2007-07-12T22:46:27Z")

</div>

John Joyce wrote:

> I've been thinking about this as well lately.  
> Since Rails is overkill for a lot of little things, it would be nice if  
> ERb had more ability.  
> ERb lacks some of the functionality and flexibility of embedded php.  
> With php you can just include a file, but ERb doesn't let you do that  
> (AFAIK).

Couldn't you just put the Erb inside the html? Like:

\<html\>\<body\>  
&nbsp;&nbsp;\<!-- stuff up here --\>  
&nbsp;&nbsp;\<%= Erb.new(IO.read(filename)).result %\>  
&nbsp;&nbsp;\<!-- stuff down here --\>  
\</body\>\</html\>

> **···**
>
> --  
> &nbsp;&nbsp;Travis Warlick
> 
> &nbsp;&nbsp;"Programming in Java is like dealing with your mom --  
> &nbsp;&nbsp;&nbsp;it's kind, forgiving, and gently chastising.  
> &nbsp;&nbsp;&nbsp;Programming in C++ is like dealing with a disgruntled  
> &nbsp;&nbsp;&nbsp;girlfriend -- it's cold, unforgiving, and doesn't tell  
> &nbsp;&nbsp;&nbsp;you what you've done wrong."

---

<div class="post-metadata">

### Author: ![James\_Britt](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@James\_Britt](https://rubytalk.org/u/James_Britt)
#### Post date: [30 July 2007 16:22 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/9 "2007-07-30T16:22:11Z")

</div>

It might be possible to use ERb (Ruby) to insert the PHP.  
And then have the server first process files with Ruby, then with PHP.  
Depends on the server. It's ugly, maybe a little slower, but probably possible.

> **···**
>
> On Jul 30, 2007, at 7:48 AM, Vadim Shevchenko wrote:
> 
> > Wayne E. Seguin wrote:
> > 
> > > On Jul 12, 2007, at 09:12 , Vadim Shevchenko wrote:
> > > 
> > > > ===========
> > > > 
> > > > Main web-server script-language is Ruby.  
> > > > I want to include PHP-code.
> > > > 
> > > > Is it posiible?
> > > 
> > > Try using SSI for the php code.
> > 
> > SSI works super, but I have such problem:  
> > I want to include in html-file some php-code one of counter-systems  
> > written on PHP.  
> > By using SSI, I must write php-code to some php-file and when this php  
> > will be included, php-script don't know about html-file, about first  
> > request uri.  
> > For counter-system it's bad variant.  
> > -- Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![Gavin\_Kistner3](https://avatars.discourse-cdn.com/v4/letter/g/dfb087/32.png) [@Gavin\_Kistner3](https://rubytalk.org/u/Gavin_Kistner3)
#### Post date: [12 July 2007 18:55 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/10 "2007-07-12T18:55:01Z")

</div>

Not quite when you want the included file to have ERB commands in it:

C:\\>type main.erb  
\<%=$foo%\>  
\<%=IO.read('inc.erb')%\>

C:\\>type inc.erb  
\<%=$foo%\>

C:\\>irb  
irb(main):001:0\> require 'erb'  
irb(main):002:0\> $foo = 'Hello World'  
irb(main):003:0\> ERB.new( IO.read( 'main.erb' ) ).run  
Hello World  
\<%=$foo%\>

> **···**
>
> On Jul 12, 12:43 pm, Jeremy Henty \<onepo...@starurchin.org\> wrote:
> 
> > On 2007-07-12, John Joyce \<dangerwillrobinsondan...@gmail.com\> wrote:
> > 
> > \> With php you can just include a file, but ERb doesn't let you do  
> > \> that (AFAIK).
> > 
> > \<%= IO.read "yes\_it\_does.txt" %\>

---

<div class="post-metadata">

### Author: ![James\_Britt](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@James\_Britt](https://rubytalk.org/u/James_Britt)
#### Post date: [12 July 2007 22:56 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/11 "2007-07-12T22:56:58Z")

</div>

Let me toy with it a bit and see how much I love/hate it.

JJ

> **···**
>
> On Jul 12, 2007, at 5:46 PM, Travis D Warlick Jr wrote:
> 
> > John Joyce wrote:
> > 
> > > I've been thinking about this as well lately.  
> > > Since Rails is overkill for a lot of little things, it would be nice if  
> > > ERb had more ability.  
> > > ERb lacks some of the functionality and flexibility of embedded php.  
> > > With php you can just include a file, but ERb doesn't let you do that  
> > > (AFAIK).
> > 
> > Couldn't you just put the Erb inside the html? Like:
> > 
> > \<html\>\<body\>  
> > &nbsp;&nbsp;\<!-- stuff up here --\>  
> > &nbsp;&nbsp;\<%= Erb.new(IO.read(filename)).result %\>  
> > &nbsp;&nbsp;\<!-- stuff down here --\>  
> > \</body\>\</html\>
> > 
> > --  
> > &nbsp;&nbsp;Travis Warlick
> > 
> > &nbsp;&nbsp;"Programming in Java is like dealing with your mom --  
> > &nbsp;&nbsp;&nbsp;it's kind, forgiving, and gently chastising.  
> > &nbsp;&nbsp;&nbsp;Programming in C++ is like dealing with a disgruntled  
> > &nbsp;&nbsp;&nbsp;girlfriend -- it's cold, unforgiving, and doesn't tell  
> > &nbsp;&nbsp;&nbsp;you what you've done wrong."

---

<div class="post-metadata">

### Author: ![jzakiya1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jzakiya1](https://rubytalk.org/u/jzakiya1)
#### Post date: [31 July 2007 03:14 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/12 "2007-07-31T03:14:57Z")

</div>

You may want to look at Erubis.  
[http://www.kuwata-lab.com/erubis/](http://www.kuwata-lab.com/erubis/)

> **···**
>
> On Jul 30, 12:22 pm, John Joyce \<dangerwillrobinsondan...@gmail.com\> wrote:
> 
> > On Jul 30, 2007, at 7:48 AM, Vadim Shevchenko wrote:
> > 
> > \> Wayne E. Seguin wrote:  
> > \>\> On Jul 12, 2007, at 09:12 , Vadim Shevchenko wrote:
> > 
> > \>\>\> ===========
> > 
> > \>\>\> Main web-server script-language is Ruby.  
> > \>\>\> I want to include PHP-code.
> > 
> > \>\>\> Is it posiible?
> > 
> > \>\> Try using SSI for the php code.
> > 
> > \> SSI works super, but I have such problem:  
> > \> I want to include in html-file some php-code one of counter-systems  
> > \> written on PHP.  
> > \> By using SSI, I must write php-code to some php-file and when this php  
> > \> will be included, php-script don't know about html-file, about first  
> > \> request uri.  
> > \> For counter-system it's bad variant.  
> > \> --  
> > \> Posted viahttp://www.ruby-forum.com/.
> > 
> > It might be possible to use ERb (Ruby) to insert the PHP.  
> > And then have the server first process files with Ruby, then with PHP.  
> > Depends on the server. It's ugly, maybe a little slower, but probably  
> > possible.

---

<div class="post-metadata">

### Author: ![Vadim\_Shevchenko](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vadim\_Shevchenko](https://rubytalk.org/u/Vadim_Shevchenko)
#### Post date: [31 July 2007 13:24 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/13 "2007-07-31T13:24:38Z")

</div>

John Joyce wrote:

> **···**
>
> > On Jul 30, 2007, at 7:48 AM, Vadim Shevchenko wrote:
> > 
> > > > Try using SSI for the php code.
> > 
> > It might be possible to use ERb (Ruby) to insert the PHP.  
> > And then have the server first process files with Ruby, then with PHP.  
> > Depends on the server. It's ugly, maybe a little slower, but probably  
> > possible.
> 
> How can I use ERB for processig PHP-code? ERB parse only Ruby-code. Or  
> not?  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![Jeremy\_Henty1](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Jeremy\_Henty1](https://rubytalk.org/u/Jeremy_Henty1)
#### Post date: [12 July 2007 21:50 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/14 "2007-07-12T21:50:18Z")

</div>

Good point!

\<%= ERB.new(IO.read("how\_about\_this\_then.erb")).result(binding) %\>

Jeremy Henty

> **···**
>
> On 2007-07-12, Phrogz \<phrogz@mac.com\> wrote:
> 
> > On Jul 12, 12:43 pm, Jeremy Henty \<onepo...@starurchin.org\> wrote:
> > 
> > > On 2007-07-12, John Joyce \<dangerwillrobinsondan...@gmail.com\> wrote:
> > > 
> > > \> With php you can just include a file, but ERb doesn't let you do  
> > > \> that (AFAIK).
> > > 
> > > \<%= IO.read "yes\_it\_does.txt" %\>
> > 
> > Not quite when you want the included file to have ERB commands in it:

---

<div class="post-metadata">

### Author: ![Vadim\_Shevchenko](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vadim\_Shevchenko](https://rubytalk.org/u/Vadim_Shevchenko)
#### Post date: [31 July 2007 06:21 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/15 "2007-07-31T06:21:37Z")

</div>

jzakiya wrote:

> **···**
>
> > On Jul 30, 12:22 pm, John Joyce \<dangerwillrobinsondan...@gmail.com\> \> wrote:
> > 
> > > \>\>\> I want to include PHP-code.  
> > > \> request uri.  
> > > \> For counter-system it's bad variant.  
> > > \> --  
> > > \> Posted viahttp://www.ruby-forum.com/.
> > > 
> > > It might be possible to use ERb (Ruby) to insert the PHP.  
> > > And then have the server first process files with Ruby, then with PHP.  
> > > Depends on the server. It's ugly, maybe a little slower, but probably  
> > > possible.
> > 
> > You may want to look at Erubis.  
> > [http://www.kuwata-lab.com/erubis/](http://www.kuwata-lab.com/erubis/)
> 
> With Erubis I can "convert" Ruby-code to PHP. I need to insert PHP-code  
> in Ruby-project.  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![James\_Britt](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@James\_Britt](https://rubytalk.org/u/James_Britt)
#### Post date: [12 July 2007 22:49 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/16 "2007-07-12T22:49:23Z")

</div>

That's OK I guess, but it's not as graceful as usual Ruby things.  
I guess I'm going to look into Camping and those others.  
I checked out the Merb site once but it was all RDoc with no solid examples.  
CGI is just too ugly, it might as well be Perl for that, I wish DreamHost would run mod\_ruby...  
I'm just finding that Rails is just way more than what I want or need. Lots of cool stuff in it, but the problem is that there is just so much there. Getting started is easy enough, but things start to grind down to a crawl as you beginning unravelling all the details. It's like any big framework, it's highly productive and useful AFTER you've spent months learning it. There's definitely a learning curve and things start to get pretty complicated pretty quickly.

It's too bad that ERb itself isn't better tutorialized.

> **···**
>
> On Jul 12, 2007, at 4:50 PM, Jeremy Henty wrote:
> 
> > On 2007-07-12, Phrogz \<phrogz@mac.com\> wrote:
> > 
> > > On Jul 12, 12:43 pm, Jeremy Henty \<onepo...@starurchin.org\> wrote:
> > > 
> > > > On 2007-07-12, John Joyce \<dangerwillrobinsondan...@gmail.com\> \>\>\> wrote:
> > > > 
> > > > > With php you can just include a file, but ERb doesn't let you do  
> > > > > that (AFAIK).
> > > > 
> > > > \<%= IO.read "yes\_it\_does.txt" %\>
> > > 
> > > Not quite when you want the included file to have ERB commands in it:
> > 
> > Good point!
> > 
> > \<%= ERB.new(IO.read("how\_about\_this\_then.erb")).result(binding) %\>
> > 
> > Jeremy Henty

---

<div class="post-metadata">

### Author: ![jzakiya1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jzakiya1](https://rubytalk.org/u/jzakiya1)
#### Post date: [31 July 2007 19:34 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/17 "2007-07-31T19:34:59Z")

</div>

Did you look at the Erubis documentation?  
[http://www.kuwata-lab.com/erubis/users-guide.04.html#lang](http://www.kuwata-lab.com/erubis/users-guide.04.html#lang)

> **···**
>
> On Jul 31, 2:21 am, Vadim Shevchenko \<veejar....@gmail.com\> wrote:
> 
> > jzakiya wrote:  
> > \> On Jul 30, 12:22 pm, John Joyce \<dangerwillrobinsondan...@gmail.com\> \> \> wrote:  
> > \>\> \>\>\> I want to include PHP-code.  
> > \>\> \> request uri.  
> > \>\> \> For counter-system it's bad variant.  
> > \>\> \> --  
> > \>\> \> Posted viahttp://www.ruby-forum.com/.
> > 
> > \>\> It might be possible to use ERb (Ruby) to insert the PHP.  
> > \>\> And then have the server first process files with Ruby, then with PHP.  
> > \>\> Depends on the server. It's ugly, maybe a little slower, but probably  
> > \>\> possible.
> > 
> > \> You may want to look at Erubis.  
> > \>[http://www.kuwata-lab.com/erubis/](http://www.kuwata-lab.com/erubis/)
> > 
> > With Erubis I can "convert" Ruby-code to PHP. I need to insert PHP-code  
> > in Ruby-project.  
> > --  
> > Posted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

### Author: ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)
#### Post date: [12 July 2007 23:00 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/18 "2007-07-12T23:00:20Z")

</div>

> \>\>\>  
> \>\>\>\> With php you can just include a file, but ERb doesn't let you do  
> \>\>\>\> that (AFAIK).  
> \>\>\>  
> \>\>\> \<%= IO.read "yes\_it\_does.txt" %\>  
> \>\>  
> \>\> Not quite when you want the included file to have ERB commands in it:  
> \>  
> \> Good point!  
> \>  
> \> \<%= ERB.new(IO.read("how\_about\_this\_then.erb")).result(binding) %\>  
> \>  
> \> Jeremy Henty  
> \>  
> That's OK I guess, but it's not as graceful as usual Ruby things.  
> I guess I'm going to look into Camping and those others.  
> I checked out the Merb site once but it was all RDoc with no solid  
> examples.

You can of course make it more graceful:

def erb\_include(path, b = nil)  
&nbsp;&nbsp;&nbsp;b = binding unless b  
&nbsp;&nbsp;&nbsp;ERB.new(IO.read(path)).result(b)  
end

\<%= erb\_include("file.erb") %\>

It's still a bit icky w/ local vars ☹ [But that's part of the reason I  
don't like templating like this anyway]

CGI is just too ugly, it might as well be Perl for that, I wish

> **···**
>
> On 7/12/07, John Joyce \<dangerwillrobinsondanger@gmail.com\> wrote:
> 
> > On Jul 12, 2007, at 4:50 PM, Jeremy Henty wrote:  
> > \> On 2007-07-12, Phrogz \<phrogz@mac.com\> wrote:  
> > \>\> On Jul 12, 12:43 pm, Jeremy Henty \<onepo...@starurchin.org\> wrote:  
> > \>\>\> On 2007-07-12, John Joyce \<dangerwillrobinsondan...@gmail.com\> \> \>\>\> wrote:  
> > DreamHost would run mod\_ruby...  
> > I'm just finding that Rails is just way more than what I want or  
> > need. Lots of cool stuff in it, but the problem is that there is just  
> > so much there. Getting started is easy enough, but things start to  
> > grind down to a crawl as you beginning unravelling all the details.  
> > It's like any big framework, it's highly productive and useful AFTER  
> > you've spent months learning it. There's definitely a learning curve  
> > and things start to get pretty complicated pretty quickly.
> > 
> > It's too bad that ERb itself isn't better tutorialized.

---

<div class="post-metadata">

### Author: ![Jeremy\_Henty1](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Jeremy\_Henty1](https://rubytalk.org/u/Jeremy_Henty1)
#### Post date: [12 July 2007 23:25 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/19 "2007-07-12T23:25:05Z")

</div>

> > \<%= ERB.new(IO.read("how\_about\_this\_then.erb")).result(binding) %\>
> 
> That's OK I guess, but it's not as graceful as usual Ruby things.

I agree, though you can pretty it up somewhat (as is pointed out  
elsewhere in this thread).

> I guess I'm going to look into Camping and those others.

I've not yet decided if my head is twisted enough to survive being  
wrapped around one of \_why's frameworks. 🙂

Jeremy Henty

> **···**
>
> On 2007-07-12, John Joyce \<dangerwillrobinsondanger@gmail.com\> wrote:
> 
> > On Jul 12, 2007, at 4:50 PM, Jeremy Henty wrote:

---

<div class="post-metadata">

### Author: ![James\_Britt](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@James\_Britt](https://rubytalk.org/u/James_Britt)
#### Post date: [1 August 2007 02:49 UTC](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035/20 "2007-08-01T02:49:56Z")

</div>

There are several forms of "eruby"  
Erubis can work for many languages, but I don't know if it can do them all at the same time.  
ERb is the Ruby standard library eruby implementation, as far as I know, it does not handle PHP  
Erubis seems cool, but the docs are a bit difficult to read.

> **···**
>
> On Jul 31, 2007, at 2:34 PM, jzakiya wrote:
> 
> > On Jul 31, 2:21 am, Vadim Shevchenko \<veejar....@gmail.com\> wrote:
> > 
> > > jzakiya wrote:
> > > 
> > > > On Jul 30, 12:22 pm, John Joyce \<dangerwillrobinsondan...@gmail.com\> \>\>\> wrote:
> > > > 
> > > > > > > > I want to include PHP-code.
> > > > > > 
> > > > > > request uri.  
> > > > > > For counter-system it's bad variant.  
> > > > > > --  
> > > > > > Posted viahttp://www.ruby-forum.com/.
> > > 
> > > > > It might be possible to use ERb (Ruby) to insert the PHP.  
> > > > > And then have the server first process files with Ruby, then with PHP.  
> > > > > Depends on the server. It's ugly, maybe a little slower, but probably  
> > > > > possible.
> > > 
> > > > You may want to look at Erubis.  
> > > > [http://www.kuwata-lab.com/erubis/](http://www.kuwata-lab.com/erubis/)
> > > 
> > > With Erubis I can "convert" Ruby-code to PHP. I need to insert PHP-code  
> > > in Ruby-project.  
> > > --  
> > > Posted viahttp://www.ruby-forum.com/.
> > 
> > Did you look at the Erubis documentation?  
> > [http://www.kuwata-lab.com/erubis/users-guide.04.html#lang](http://www.kuwata-lab.com/erubis/users-guide.04.html#lang)
> > 
> > b

[Next page](https://rubytalk.org/t/ruby-and-php-code-in-html-page/39035.md?page=2)
