Move to XML

move functions from text to xml
This commit is contained in:
Adam Magness 2018-11-03 13:08:01 -04:00
parent 95a41699cf
commit 84e900d96f
2 changed files with 44 additions and 93 deletions

View file

@ -462,4 +462,43 @@ class XML
return $first_item->attributes;
}
/**
* escape text ($str) for XML transport
* @param string $str
* @return string Escaped text.
*/
public static function xmlify($str)
{
$buffer = htmlspecialchars($str, ENT_QUOTES, "UTF-8");
$buffer = trim($buffer);
return $buffer;
}
/**
* undo an xmlify
* @param string $s xml escaped text
* @return string unescaped text
*/
public static function unxmlify($s)
{
$ret = htmlspecialchars_decode($s, ENT_QUOTES);
return $ret;
}
/**
* apply xmlify() to all values of array $val, recursively
* @param array $val
* @return array
*/
public static function arrayXmlify($val)
{
if (is_bool($val)) {
return $val?"true":"false";
} elseif (is_array($val)) {
return array_map('XML::arrayXmlify', $val);
}
return self::xmlify((string) $val);
}
}