Skip to content

Instantly share code, notes, and snippets.

@kek
Created July 20, 2012 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kek/3153275 to your computer and use it in GitHub Desktop.
Save kek/3153275 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