Archive for the Category: PHP
Post shows simple PHP function of how to create XML string from associative array. In foreach loop, each item will be closed within XML tag named on key part of array member. After loop is finished, function returns XML string. I also created options to add parent node and write nodes in uppercase.
Suppose you have to send four values: element Id, table, row and column compounded in one URL parameter. That is simple, parameters can be concatenated and delimited with special character. But how to send multiple of these complex URL parameters?
This post shows two examples of how to find the week list for the current date. Input parameter is date, and the output is date list from Monday till Sunday. First example is done with classic algorithm while second example uses ISO week date format.
You can find a lot of backup solutions for Linux server. From expensive and multi platform software like NetBackup to simple BASH scripts. As a Linux (LAMP) administrator, I decided to write my own backup script in PHP. I wanted to backup important locations like Web root, crontabs, /etc, /root and copy MySQL dump files.
In PHP you can find files with function glob. The glob function searches for all the pathnames matching pattern according to the rules used by the libc glob function, which is similar to the rules used by common shells. It is nice, but it works for the current directory only. If you need function to search whole directory subtree, then it can be done with few lines more.
In this post you will find how to create thumbnail images with PHP. Function uses GD library so it doesn't depend on installed utilities like ImageMagick. On the other hand, you will have to install php-gd module - "yum install php-gd". Function will resize JPEG, PNG and GIF images, while PNG and GIF without losing their transparency.
PHP can be used to create and manipulate image files in a variety of different image formats. This post shows how to create thumbnail image in the same directory as the original image. Instead of GD library, I used utilities from ImageMagick suite of tools so your PHP shouldn't have a GD module installed.
In this post you will find how to configure PHP to log errors and warnings to the separate log file - error_php. You can place error_php wherever you want, but I will suggest to choose the /tmp directory ...
In my post "From MySQL to XML with PHP", I described how to generate XML from the MySQL database. Instead of printing out XML, generated XML can be buffered and transformed with XSL to the HTML. Maybe it sounds complicated for a simple process of displaying MySQL data on the WEB page. But if you set a WEB architecture this way, you will have a separated presentation layer from the database and business logic.
As I caught myself in process of writing PHP "log" function several times I have finally decided to create a simple Logging PHP class. After Logging class initialization, first call of lwrite method will open log file implicitly and write line to the file. Every other lwrite will use already opened file pointer until closing file with lclose.
PHP XML generator can be written in less then 100 lines. In this example, data from the MySQL database are converted to the XML. PHP function sql2xml has optional second parameter to describe the XML hierarchy, while first parameter is SQL query. Second parameter is string in form of integers separated by commas.
With this simple PHP script, you'll be able to monitor the availability of Web servers. Write a list of URLs to monitor and run the script from cron. If a site becomes unavailable, monitor PHP script will generate alert and send e-mail to the default e-mail address. Monitor script is also able to send e-mail message to the various e-mail address (e-mail address per URL).