1 | <?php |
||
22 | class Text |
||
23 | { |
||
24 | /** |
||
25 | * Control characters array |
||
26 | * |
||
27 | * @var string[] |
||
28 | */ |
||
29 | private static $controlCharacters = array(); |
||
30 | |||
31 | /** |
||
32 | * Build control characters array |
||
33 | */ |
||
34 | 1 | private static function buildControlCharacters() |
|
35 | { |
||
36 | 1 | for ($i = 0; $i <= 19; ++$i) { |
|
37 | 1 | if ($i != 9 && $i != 10 && $i != 13) { |
|
38 | 1 | $find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_'; |
|
39 | 1 | $replace = chr($i); |
|
40 | 1 | self::$controlCharacters[$find] = $replace; |
|
41 | 1 | } |
|
42 | 1 | } |
|
43 | 1 | } |
|
44 | |||
45 | /** |
||
46 | * Convert from PHP control character to OpenXML escaped control character |
||
47 | * |
||
48 | * Excel 2007 team: |
||
49 | * ---------------- |
||
50 | * That's correct, control characters are stored directly in the shared-strings table. |
||
51 | * We do encode characters that cannot be represented in XML using the following escape sequence: |
||
52 | * _xHHHH_ where H represents a hexadecimal character in the character's value... |
||
53 | * So you could end up with something like _x0008_ in a string (either in a cell value (<v>) |
||
54 | * element or in the shared string <t> element. |
||
55 | * |
||
56 | * @param string $value Value to escape |
||
57 | * @return string |
||
58 | */ |
||
59 | 1 | public static function controlCharacterPHP2OOXML($value = '') |
|
60 | { |
||
61 | 1 | if (empty(self::$controlCharacters)) { |
|
62 | 1 | self::buildControlCharacters(); |
|
63 | 1 | } |
|
64 | |||
65 | 1 | return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Return a number formatted for being integrated in xml files |
||
70 | * @param float $number |
||
71 | * @param integer $decimals |
||
72 | */ |
||
73 | 1 | public static function numberFormat($number, $decimals) |
|
77 | |||
78 | /** |
||
79 | * @param int $dec |
||
80 | * @link http://stackoverflow.com/a/7153133/2235790 |
||
81 | * @author velcrow |
||
82 | */ |
||
83 | 1 | public static function chr($dec) |
|
99 | |||
100 | /** |
||
101 | * Convert from OpenXML escaped control character to PHP control character |
||
102 | * |
||
103 | * @param string $value Value to unescape |
||
104 | * @return string |
||
105 | */ |
||
106 | 1 | public static function controlCharacterOOXML2PHP($value = '') |
|
107 | { |
||
108 | 1 | if (empty(self::$controlCharacters)) { |
|
109 | self::buildControlCharacters(); |
||
110 | } |
||
111 | |||
112 | 1 | return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value); |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Check if a string contains UTF-8 data |
||
117 | * |
||
118 | * @deprecated 0.2.4 Use `Zend\Stdlib\StringUtils::isValidUtf8` instead. |
||
119 | * |
||
120 | * @param string $value |
||
121 | * @return boolean |
||
122 | */ |
||
123 | 1 | public static function isUTF8($value = '') |
|
127 | |||
128 | /** |
||
129 | * Return UTF8 encoded value |
||
130 | * |
||
131 | * @param string $value |
||
132 | * @return string |
||
133 | */ |
||
134 | public static function toUTF8($value = '') |
||
135 | { |
||
136 | if (!is_null($value) && !self::isUTF8($value)) { |
||
|
|||
137 | $value = utf8_encode($value); |
||
138 | } |
||
139 | |||
140 | return $value; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Returns unicode from UTF8 text |
||
145 | * |
||
146 | * The function is splitted to reduce cyclomatic complexity |
||
147 | * |
||
148 | * @param string $text UTF8 text |
||
149 | * @return string Unicode text |
||
150 | * @since 0.11.0 |
||
151 | */ |
||
152 | 1 | public static function toUnicode($text) |
|
156 | |||
157 | /** |
||
158 | * Returns unicode array from UTF8 text |
||
159 | * |
||
160 | * @param string $text UTF8 text |
||
161 | * @return array |
||
162 | * @since 0.11.0 |
||
163 | * @link http://www.randomchaos.com/documents/?source=php_and_unicode |
||
164 | */ |
||
165 | 1 | public static function utf8ToUnicode($text) |
|
196 | |||
197 | /** |
||
198 | * Returns entites from unicode array |
||
199 | * |
||
200 | * @param array $unicode |
||
201 | * @return string |
||
202 | * @since 0.11.0 |
||
203 | * @link http://www.randomchaos.com/documents/?source=php_and_unicode |
||
204 | */ |
||
205 | 1 | private static function unicodeToEntities($unicode) |
|
217 | |||
218 | /** |
||
219 | * Return name without underscore for < 0.10.0 variable name compatibility |
||
220 | * |
||
221 | * @param string $value |
||
222 | * @return string |
||
223 | */ |
||
224 | 1 | public static function removeUnderscorePrefix($value) |
|
234 | } |
||
235 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.