O'Reilly logo

PHP Hacks by Jack D. Herrington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #94. Generate Flash Movies on the Fly

Use Ming to create dynamic Flash movies from PHP.

Have you ever wanted to make a web graphic have a little more pizzazz or zing? We all have at some point. One way to do this is to use the Macromedia Flash format (also known as the SWF format). But how do you do that with just open source tools? Well, there is a PHP module called Ming that saves the day (ironic, isn't it? Ming saves Flash?). It allows you to generate full-blown Flash files on the fly. This hack will show you how to pull that off with a Flash application that dynamically generates charts.

The Code

Save the code in Example 9-13 as data.php.

Example 9-13. Some XML to be rendered by Flash

<?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 header('Content-type: application/xml'); echo("<?xml version=\"1.0\" ?>\n"); ?> <GRAPH TYPE="BAR"> <TITLE>Revenues 2005</TITLE> <YAXIS>Dollars <RANGE MIN="0" MAX="50000" /> </YAXIS> <XAXIS>Period </XAXIS> <DATA> <?php $colors = array( "0xFF0000", "0xFFFF00", "0xFF00FF", "0x00FFFF", "0x00FF00" ); srand((double)microtime()*1000000); for ($i = 1; $i < 7; $i++) { $clr = $colors[ ($i - 1) % count($colors) ] ; $val = rand(10000,45000); echo("<D$i>$val<COLOR C=\"$clr\" /></D$i>\n"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required