Page 24 - Open Soource Technologies 304.indd
P. 24
Web Technologies-I
Notes For example, Example also creates buttons. However, it is run from the command line, not from
a web server. The q-option to the php executable inhibits the generation of HTTP headers.
Shell-based PHP program to create a button
#!/usr/local/bin/php –q
<?
php if ($argc != 3)
{
die(“usage: button-cli filename message\n”);
}
list(, $filename, $message) = $argv; // load font and image, calculate width of text
$font = ‘Arial.ttf’;
$size = 12;
$im = ImageCreateFromPNG(‘button.png’);
$tsize = imagettfbbox($size,0,$font,$message);
// center $dx = abs($tsize[2]-$tsize[0]);
$dy = abs($tsize[5]-$tsize[3]);
$x = ( imagesx($im) - $dx ) / 2;
$y = ( imagesy($im) - $dy ) / 2 + $dy; // draw text $black = ImageColorAllocate($im,0,0,0);
ImageTTFText($im, $size, 0, $x, $y, $black, $font, $message); // return image ImagePNG($im,
$filename);
?>
Save Example to button-cli and run it:
# ./button-cli usage: button-cli filename message # ./button-cli php-button.png “PHP Button” #
ls -l php-button.png-rwxr-xr-x 1 gnat gnat 1837 Jan 21 22:17 php-button.png
Now that you have had a taste of what is possible with PHP, you are ready to learn how to
program in PHP. We start with the basic structure of the language, with special focus given to
user-defined functions, string manipulation, and object-oriented programming. Then we move
to specific application areas such as the Web, databases, graphics, XML, and security. We finish
with quick references to the built-in functions and extensions.
Develop a shell-based PHP program to create a textbox.
CppCMS vs PHP
Benchmark
In this benchmark two technologies were compared: CppCMS and PHP.
This written using CppCMS technology was compared to WordPress blog powered by PHP5.
Contd...
18 LOVELY PROFESSIONAL UNIVERSITY