IBM i > TIPS & TECHNIQUES > APPLICATION DEVELOPMENT

Beginning PHP Programming


In part one we covered setting up PHP and running it on your iSeries server. Here, I offer coding tips and explore some of the possibilities that PHP can potentially unlock.

 

Even if you're new to PHP, chances are you'll find it familiar: The scripting languages syntax is similar to C++, meaning that C++ as well as C, Java* and Perl users should find PHP easy to pick up.

Conditionals and Loops
Part one introduced the echo function and the assignment (=) operator. However, there's little you can do with these on their own. That's where conditionals and loops come in.

This example introduces several new concepts:



  if (isset($_GET['printme'])) {
        echo ("

$_GET['contents']
");
  } else {
        for ($i = 0; $i < 10; $i++) {
                echo ($i . "
\n");
        }
  }
?>

 

 

The first line contains this bit of code: . Lets break this down. While last month's samples incorporated ". Whatever is between these tags-""-is what's printed to the Web page.

Another new concept is "$_GET['title']," which is an array containing a list of variables passed to the Web page through the GET method of HTTP. Suppose you save this code in the IFS under your Web server root directory as webpage.php and that it's accessible via this URL:

http://mywebserver/webpage.php?title=Programming%20PHP&contents=Programming%20PHP%20is%20fun%21&printme=true

 

David Stockton is a programmer with J.D. Edwards World Solutions Company. He can be reached at his Web site davidstockton.com.


comments powered by Disqus

Advertisement

Advertisement

2017 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

A PPP Monitor Utility

Here's a program developed to programmatically obtain the status of a PPP connection

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters