Archive for the Category: PHP

Convert PHP associative array to XML

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.

Leave a comment

Reading multiple parameters in PHP

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?

14 Comments

Week list for the current date in PHP

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.

18 Comments

Backup Linux server with PHP

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.

Leave a comment

Find files with PHP

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.

1 Comment

Create thumbnail with PHP (2)

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.

5 Comments

Create thumbnail with PHP (1)

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.

Leave a comment

Log PHP errors to the separate file

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 ...

Leave a comment