XML Helper¶
The XML Helper file contains functions that assist in working with XML data.
Loading this Helper¶
This helper is loaded using the following code:
<?php
helper('xml');
Available Functions¶
The following functions are available:
xml_convert($str[, $protect_all = false])¶
-
Parameters
- $str
stringThe text string to convert - $protect_all
boolWhether to protect all content that looks like a potential entity instead of just numbered entities, e.g., &foo;
- $str
-
Returns: XML-converted string
-
Return type:
string
Takes a string as input and converts the following reserved XML characters to entities:
- Ampersands: &
- Less than and greater than characters: < >
- Single and double quotes: ' "
- Dashes: -
This function ignores ampersands if they are part of existing numbered character entities, e.g., {. Example:
<?php
$string = '<p>Here is a paragraph & an entity ({).</p>';
$string = xml_convert($string);
echo $string;
Outputs:
<p>Here is a paragraph & an entity ({).</p>