Skip to content

Instantly share code, notes, and snippets.

@ramn
Forked from kek/gist:3153275
Created September 1, 2012 10:51
Show Gist options
  • Save ramn/3569514 to your computer and use it in GitHub Desktop.
Save ramn/3569514 to your computer and use it in GitHub Desktop.
Writing a CGI script with templates. For PHP programmers
#!/usr/bin/ruby
require 'cgi'
require 'erb'
cgi = CGI.new('html')
template = <<TEMPLATE
<html>
<head>
<title>Ruby as PHP</title>
</head>
<body>
<h1>Loop</h1>
<ul>
<% 1.upto(5).each do |i| %>
<li>Number <%= i %></li>
<% end %>
</ul>
</body>
TEMPLATE
html = ERB.new(template).result(binding)
cgi.out { html }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment