1. Home
  2. Computing & Technology
  3. Python

Part 1: Laying the Groundwork with HTML, CGI, and PHP

From Al Lukaszewski, for About.com

8 of 10

PHP Plays Middleman Between Python and the HTML Interface

Now for the PHP script. It reads as follows:

<?php
$results = shell_exec ("./RSSReader.py \"" . $_POST["selection"> . "\"") ;


print "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">

<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=utf-8\">
<title>About.com's Python-Powered RSS Reader</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"./base.css\" />
</head>
<body bgcolor = \"lightblue\">
<font color = \"black\">
<h4>
";

print $results;
print "</h4> </body> </html>";
?>

Essentially, this merely takes the form data from the web page and patches it through to the Python backend. If you do not understand how this works, see my tutorial on PHP-Javascript-Python as a CGI replacement.

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.