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.

Categories PHP

Styling Apache directory listings

In this post you will find how to make stylish listing generated by the Apache server. This is not just another CSS solution. The trick is in configuring Apache to generate XML directory list and to use browser (IE, FF, Opera, Safari …) to transform XML to the HTML. You will have full freedom to modify and style auto generated directory listings.

Create XML from directory list with Apache

In Apache world, the index of a directory can come from one of two sources – a file written by the user, typically called index.html or a listing generated by the server. If you enable automatic index generation (with Options +Indexes), Apache will create a HTML directory list for the URL without index page. With a few lines in httpd.conf, directory list can become a XML document.

From MySQL to HTML with PHP and XML

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.

From MySQL to XML with PHP

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.