Openlot Systems

4.4 Can you show me some examples serving WAP via PHP?

This example produces a very useful application called PizzaCalc. It inputs the total cost of your pizza bill and the number of people who've had pizza, and then produces the cost per person.

The application produces a deck with one dynamic card, either called "calc" or "input" based on the action. Notice all the escaped characters such as the double quotes. It also shows simple variable handling, and how to pass variables from one card to another.

With a WML browser, you can try the application here or you can simply go to the much-easier-to-type URL of and choose the application from there.

<?
  header("Content-type: text/vnd.wap.wml");
  echo("<?xml version=\"1.0\"?>\n");
  echo("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://...\">\n\n");
  echo("<!-- The application PizzaCalc was originally made by The Crusaders on the Commodore Amiga -->\n");
  echo("<!-- It was unfortunately not possible to emulate the crap interger handling of the original program -->\n");
?>
<wml>
<?
  if($action == "calc") {
    echo("<card id=\"result\" title=\"PizzaCalc\">\n");
    echo("<do type=\"prev\" label=\"Back\">\n");
    echo("<go href=\"pizzacalc.asp#input\"/>\n");
    echo("</do>\n");
    echo("<p>\n");
    echo("The cost per eater will be ".$total / $eaters."<br/>\n");
  }
  else {
    echo("<card id=\"input\" title=\"PizzaCalc\">\n");
    echo("<p>\n");
    echo("<anchor>Split Pizza bill <go href=\"pizzacalc.asp?total=\$(total)&eaters=\$(eaters)&action=calc\"/></anchor>\n");
    echo("<br/>\n");
    echo("Total cost: <input type=\"text\" name=\"total\" format=\"*N\"/>\n");
    echo("Eaters: <input type=\"text\" name=\"eaters\" format=\"*N\"/>\n");
  }
?>
</p>
</card>
</wml>
[ Main ]   [ 04 - Serving WML contents ]