WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : ini file to XML converter
Categories : PHP, XML Click here to Update Your Picture
Exception e
Date : Jul 30th 2005
Grade : 2 of 5 (graded 2 times)
Viewed : 4530
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Exception e
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
/**
* parses a ini file into a xml
* If $useSections is true, then evey setting must fall under a section.<br>For more information about the format of ini-files, have a look at the function <code>parse_ini_file()</code> in the php manual.
* @param        string $filePath
* @param        bool $useSections determine whether the ini-settings must be grouped by there sections
* @return        DomDocument holding a xml representation of the ini-file
*/
function iniToXML($filePath, $useSections = false)        {
        $aIni = parse_ini_file($filePath, $useSections);
        $dom = new DOMDocument('1.0', 'iso-8859-1');
        $root = $dom->appendChild($dom->createElement('root'));
        if (!$useSections)        {
                appendIniSettings($root, $aIni);
        } else        {
                foreach ($aIni as $sectionName => $iniSettings)        {
                        $section = $root->appendChild($dom->createElement('section'));
                        $section->setAttribute('name', $sectionName);
                        appendIniSettings($section, $iniSettings);
                }
        }
        return $dom;
}

function appendIniSettings($element, $iniSettings)        {
        $doc = $element->ownerDocument;
        foreach ($iniSettings as $prop => $value)        {
                $setting = $element->appendChild($doc->createElement('setting', $value));
                $setting->setAttribute('name', $prop);
        }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Convert flat ini file into xml</title>
</head>

<body>
NOTE: this code requires at least php5!
<?php
/* EXAMPLE OF USAGE */

        // Convert ini file into XML, with use of sections
$iniXML = iniToXML('sample.ini', true);
        //use formatOuput to create a nice indention, but it is only used for aesthetical reasons
$iniXML->formatOutput = true;
        // Now we can print the resulting xml
echo '<pre>'.htmlentities($iniXML->saveXML()).'</pre>';
        // or write it to a file named sample.xml
file_put_contents('sample.xml', $iniXML->saveXML());
?>
</body>
</html>
;** FILE sample.ini
; Save this file as sample.ini in the same directory as the example php file.

; This is a sample configuration file
; Comments start with ';', as in php.ini
[database]
datebaseName        = test_db
dabatebaseUser        = userA
datebasePass        = secure

[application]
caching = false


[other section]
property = value



XMLManipulation
Categories : PHP, XML, SimpleXML
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
A very basic and fast XML parser
Categories : PHP, PHP Classes, XML
Simple newsreader script
Categories : PHP, XML, Rich Site Summary (RSS)
RSS parser using PHP5 and simpleXML
Categories : Rich Site Summary (RSS), PHP, XML
Glossword - glossary compiler
Categories : Content Management, PHP, MySQL, XML
Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +)
Categories : PHP, Ecommerce, XML, Web Services, CURL
XML easy parser
Categories : PHP, XML
MySQL or SQL Query to XML Output
Categories : PHP, MySQL, XML, Databases
XML Menu
Categories : PHP, PHP Classes, Navigation, XML, XSL
Directory Listing To XML : Outputs XML File of a Given Directory Listing
Categories : PHP, PHP Classes, XML, Directories
Trivia Quiz program using XML, XSLT and PHP
Categories : PHP, XML, XSLT
Dynamic Loading of XML array data into ComboBox and Display XML data using PHP + DOM + Javascript.
Categories : PHP, Java Script, DOM XML, XML, Arrays
SAPIPROCESSOR - is a compact XML-based CMS toolkit
Categories : PHP, Content Management, XML
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel