February 27, 2021
Hot Topics:

WML Scripting Tips and Integration with PHP

  • By Steve Schafer
  • Send Email »
  • More Articles »

This series of articles describes how to provide Web content to mobile devices through WML (Wireless Markup Language). This article covers some additional uses for WMLScript and how to integrate PHP with WML. Future articles will cover more advanced PHP and WML techniques.

Note: These articles cover WML and WMLScript version 1.1, which are supported by the majority of mobile devices in use today. The articles assume a working knowledge of HTML and general Web technologies, and further assume that you have read the previous article(s) in this series.


In the last article we discussed how to use WMLScript to perform basic scripting tasks within your WML pages. As mentioned in that article, WMLScript can be used to validate input and perform basic operations on WML variables. WMLScript can also be used to control the display of various cards and the information contained on them. For example, the following code will display an animation by changing an image's source and refreshing a card every two seconds:


  <card id="card1">
    <onevent type="onenterforward">
      <setvar name="num" value="1" />
      <setvar name="image" value="image1.wbmp" />
    <onevent type="ontimer">
      <go href="junk.wmls#main()" />
    <timer value="20" />
    <p><img alt="$(image)" src="$(image)" /></p>

  <card id="card2">
  <p>Animation Done!</p>


extern function main() {
var Num = WMLBrowser.getVar("num");
var Image = "";

if (Num < 9) {
  Image = "image" + Num + ".wbmp";
  WMLBrowser.setVar("num", Num);
  WMLBrowser.setVar("image", Image);
} else {

The deck (animation.wml) sets two variables and forces a refresh. These are the variables:

num:The number to append to the image source
image:  The starting image source (image1.wbmp)

Every two seconds, the main() function in animation.wmls is called. This function adds one to "num," creates a new image source (image<num>.wbmp), and refreshes the card, which causes the new image to be displayed. After the ninth image (image9.wbmp) is displayed, the script goes to the second card in the deck, ending the animation.

Note: The above example assumes that your animation consists of nine images that, when displayed sequentially, create the animation.

WMLScripting is flexible and brings basic scripting to WML. However, it's possible to lend more programming power to WML by infusing it with PHP, as covered in the next section.

Page 1 of 3

This article was originally published on August 19, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date