-
Notifications
You must be signed in to change notification settings - Fork 1
/
xml.php
63 lines (53 loc) · 1.38 KB
/
xml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
XML data conversion tools for the PHP Fat-Free Framework
The contents of this file are subject to the terms of the GNU General
Public License Version 3.0. You may not use this file except in
compliance with the license. Any of the license terms and conditions
can be waived if you get permission from the copyright holder.
Copyright (c) 2009-2012 F3::Factory
Bong Cosca <[email protected]>
@package Network
@version 2.0.12
**/
//! XML data conversion tools
class XML extends Base {
static
//! XML translation table
$xmltab=array();
/**
Return XML translation table
@return array
@param $latin boolean
@private
**/
private static function table($latin=FALSE) {
if (!isset(self::$xmltab[(int)$latin])) {
$xl8=get_html_translation_table(HTML_ENTITIES,ENT_COMPAT);
foreach ($xl8 as $key=>$val)
$tab[$latin?$val:$key]='&#'.ord($key).';';
self::$xmltab[(int)$latin]=$tab;
}
return self::$xmltab[(int)$latin];
}
/**
Convert plain text to XML entities
@return string
@param $str string
@param $latin boolean
@public
**/
static function encode($str,$latin=FALSE) {
return strtr($str,self::table($latin));
}
/**
Convert XML entities to plain text
@return string
@param $str string
@param $latin boolean
@public
**/
static function decode($str,$latin=FALSE) {
return strtr($str,array_flip(self::table($latin)));
}
}