Parses a XML file using XML_Parser.

Available Options
Option Data Type Default value Description
version string 1.0 The XML version to use.
encoding string ISO-8859-1 The content encoding to use when parsing and storing data.
name string conf As with PHPArray, this defines the name of the global configuration root.
indent string    The character used for indentation when writing the XML document, if any. By default, two spaces are used.
linebreak string \n The line-breaking character(s) to use when writing the XML document.
addDecl boolean TRUE Controls whether the XML declaration is added to the start of the XML document.
useAttr boolean TRUE Controls whether attributes are parsed and saved.
isFile boolean TRUE If TRUE, the first argument to parseConfig() will be taken as the file name for the XML file to load. If FALSE, the argument will be taken as the XML data itself and parsed accordingly.
useCData boolean FALSE Controls whether data is enclosed in CDATA blocks.

To utilize the XML container, you need to have the XML_Parser package installed (optional dependency).

Writing a config file with the XML container

require_once 'Config.php';

$conf = new Config();
$root $conf->getRoot();
$root->createComment('Demo config file with XML container');
//we need a main section, otherwise we get invalid XML
// see http://pear.php.net/bugs/bug.php?id=18357
$main $root->createSection('config');

$dbsect $main->createSection('database');

//this is a nested section
$subsect $dbsect->createSection('settings');

$r $conf->writeConfig(
'encoding' => 'UTF-8',
'indent'   => ' ',
if (
PEAR::isError($r)) {
$r->getMessage() . "\n";

Generated file

<?xml version="1.0" encoding="UTF-8"?>
<!-- Demo config file with XML container -->
   <reconnect />
PHPConstants (Previous) Config class (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.