Chapter 13. What Else Can You Do with PHP?
This book covers the fundamental PHP topics that you need for everyday dynamic web site development, such as handling forms, working with a database, and remembering users with sessions. Beyond that core, though, PHP can do much more. Here are a few paragraphs, an example or two, and links to more info about many other capabilities of PHP.
Graphics
Your
PHP programs can produce more than just HTML web
pages. With the GD extension, they can also
dynamically generate graphicsâfor example, you can create custom buttons. Example 13-1 draws a rudimentary button whose
text comes from the button
URL variable.
<?php // GD's built-in fonts are numbered from 1 - 5 $font = 3; // Calculate the appropriate image size $image_height = intval(imageFontHeight($font) * 2); $image_width = intval(strlen($_GET['button']) * imageFontWidth($font) * 1.3); // Create the image $image = imageCreate($image_width, $image_height); // Create the colors to use in the image // gray background $back_color = imageColorAllocate($image, 216, 216, 216); // blue text $text_color = imageColorAllocate($image, 0, 0, 255); // black border $rect_color = imageColorAllocate($image, 0, 0, 0); // Figure out where to draw the text // (Centered horizontally and vertically $x = ($image_width - (imageFontWidth($font) * strlen($_GET['button']))) / 2; $y = ($image_height - imageFontHeight($font)) / 2; // Draw the text imageString($image, $font, $x, $y, ...
Get Learning PHP 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.