3
declare(strict_types=1);
6
* This file is part of CodeIgniter 4 framework.
8
* (c) CodeIgniter Foundation <admin@codeigniter.com>
10
* For the full copyright and license information, please view
11
* the LICENSE file that was distributed with this source code.
14
// CodeIgniter XML Helpers
16
if (! function_exists('xml_convert')) {
18
* Convert Reserved XML characters to Entities
20
function xml_convert(string $str, bool $protectAll = false): string
22
$temp = '__TEMP_AMPERSANDS__';
24
// Replace entities to temporary markers so that
25
// ampersands won't get messed up
26
$str = preg_replace('/&#(\d+);/', $temp . '\\1;', $str);
28
if ($protectAll === true) {
29
$str = preg_replace('/&(\w+);/', $temp . '\\1;', $str);
50
$str = str_replace($original, $replacement, $str);
52
// Decode the temp markers back to entities
53
$str = preg_replace('/' . $temp . '(\d+);/', '&#\\1;', $str);
55
if ($protectAll === true) {
56
return preg_replace('/' . $temp . '(\w+);/', '&\\1;', $str);