Home arrow PHP arrow Page 3 - WAP-Enabling a Website with PHP3

Switching to WML - PHP

Ever wonder what it took to get a site to work on those new "web-enabled" cell phones? This short tutorial will do just that by giving you the basics of making your site WAP-enabled using PHP.Reprinted from http://www.gbdirect.co.uk/ with permission.

TABLE OF CONTENTS:
  1. WAP-Enabling a Website with PHP3
  2. How it Works
  3. Switching to WML
  4. Conclusions
By: Mike Banahan
Rating: starstarstarstarstar / 23
June 12, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

After we got the HTML site going, the next task was to WAP it up. The first concern was how much we would have to hack php3 to tell it not to emit a first line that says


Content-type: text/html

Although I couldn't find it documented anywhere, I found to my deep and abiding joy that if you use the php3 header() function to output a different content-type header, that suppresses the default. Bingo! Every WML card deck now includes this php fragment at the top:


<? header("Content-type: text/vnd.wap.wml"); echo "<?xml version=\"1.0\"?>\n"; echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"" . " \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n"; ?>
and that deals with all the usual crud you have to cough out to get started with WAP. From there on it was plain sailing. It took six hours to a) learn enough WML to get something done and b) implement it. I used Steve Mann's book "Programming Applications with the Wireless Application Protocol" (Wiley, ISBN 0-471-32754-9) as my reference, plus a few downloaded tutorials from places like Waptastic for backup. I wouldn't recommend any of them. Considering how restricted the WML language is, you would have thought it wouldn't take much explaining, but I have yet to see a decent tutorial on it. Maybe I am just too dim to pick it up easily. That might also account for how limited our current WAP version of the site is.

Of course you can't rely on WML being correct without testing it. If there is a WML weblint-alike, I'd like to find it, but haven't looked hard enough yet. It would be a big help to ensure that the WML is well-formed on the way out. You also have to check that your WAP site `works', to the degree that you can make anything work through such a limited medium. There are a number of WAP phone simulators around. There is a web-based one at Gelon as well as others from phone.com and the marvellously named Slob-Trot in Finland. Sadly both the latter two only run under Windows so far as I can tell, but vmware came to the rescue. Or, at least it did for the Slob Trot browser, the phone.com version ran but didn't paint any images on the screen. I later found a native Windows machine and it seemed OK on that.

Using the simulators to test the WML allowed the php3 templates to be written very quickly. Here is the full `place' template:


<? require("stdwaphdr.tpl"); require('stdplace.tpl'); ?> <? $votepics = array("xx", "x", "+", "++", "+++"); ?> <card title="Search results" id="first"> <p> <?htmTplacetypename();?>(s) near <? htmT("placesearch"); ?><br/> <? if(isset($places)): ?> <? $placelist = new PlaceList; $placelist->import($places); $placelist->reset(); $count = 1; while($place = $placelist->next()): ?> <? echo htmlspecialchars("\"$place->name\", " . $place->county_address()); ?> <? printf("(%.2fm) ", ($place->distance_km()*100/1.6)/100); ?><br/> <? if(isset($Objects[$place->unique_id . "votes"])){ $arrayref = $Objects[$place->unique_id. "votes"]; // echo "Scores:"; $first = 1; while(list($key, $value) = each($arrayref)){ $idx = $value - 1; if($idx < 0) continue; $vname = $Objects["voteranktoshortnames"][$key]; if ($first) { $first = 0; } else { echo ", "; } if (($idx < sizeof($votepics)) && ($idx >= 0)) { echo "$vname $votepics[$idx]"; } else { error("Vote value out of range"); } } echo "<br/>\n"; } else { // echo "No votes yet<br/>\n"; } ?> <? endwhile; ?> <? else: ?> No matches! <? endif; ?> Go back<anchor title="back"><prev>back</prev></anchor> </p> </card> <? require("stdwapftr.tpl"); ?>


This article copyright GBdirect Ltd 2000. All rights reserved. Reprinted from http://www.gbdirect.co.uk/ with permission.

 
 
>>> More PHP Articles          >>> More By Mike Banahan
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: