]> git.mxchange.org Git - friendica.git/blob - src/Util/Strings.php
Move methods to new Util/Strings class
[friendica.git] / src / Util / Strings.php
1 <?php
2 /**
3  * @file src/Util/Strings.php
4  */
5
6 namespace Friendica\Util;
7
8 /**
9  * @brief This class contains methods to modify/transform strings.
10  */
11 class Strings
12 {
13     /**
14          * escape text ($str) for XML transport
15          * @param string $str
16          * @return string Escaped text.
17          */
18         public static function escape($str)
19         {
20                 $buffer = htmlspecialchars($str, ENT_QUOTES, "UTF-8");
21                 $buffer = trim($buffer);
22
23                 return $buffer;
24         }
25
26         /**
27          * undo an escape
28          * @param string $s xml escaped text
29          * @return string unescaped text
30          */
31         public static function unescape($s)
32         {
33                 $ret = htmlspecialchars_decode($s, ENT_QUOTES);
34                 return $ret;
35         }
36
37         /**
38          * apply escape() to all values of array $val, recursively
39          * @param array $val
40          * @return array
41          */
42         public static function arrayEscape($val)
43         {
44                 if (is_bool($val)) {
45                         return $val?"true":"false";
46                 } elseif (is_array($val)) {
47                         return array_map('XML::arrayEscape', $val);
48                 }
49                 return self::escape((string) $val);
50         }
51 }