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() |
|
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 = '') |
|
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 = '') |
|
114 | |||
115 | /** |
||
116 | * Check if a string contains UTF-8 data |
||
117 | * |
||
118 | * @param string $value |
||
119 | * @return boolean |
||
120 | */ |
||
121 | 1 | public static function isUTF8($value = '') |
|
125 | |||
126 | /** |
||
127 | * Return UTF8 encoded value |
||
128 | * |
||
129 | * @param string $value |
||
130 | * @return string |
||
131 | */ |
||
132 | public static function toUTF8($value = '') |
||
133 | { |
||
134 | if (!is_null($value) && !self::isUTF8($value)) { |
||
135 | $value = utf8_encode($value); |
||
136 | } |
||
137 | |||
138 | return $value; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Returns unicode from UTF8 text |
||
143 | * |
||
144 | * The function is splitted to reduce cyclomatic complexity |
||
145 | * |
||
146 | * @param string $text UTF8 text |
||
147 | * @return string Unicode text |
||
148 | * @since 0.11.0 |
||
149 | */ |
||
150 | 1 | public static function toUnicode($text) |
|
154 | |||
155 | /** |
||
156 | * Returns unicode array from UTF8 text |
||
157 | * |
||
158 | * @param string $text UTF8 text |
||
159 | * @return array |
||
160 | * @since 0.11.0 |
||
161 | * @link http://www.randomchaos.com/documents/?source=php_and_unicode |
||
162 | */ |
||
163 | 1 | public static function utf8ToUnicode($text) |
|
194 | |||
195 | /** |
||
196 | * Returns entites from unicode array |
||
197 | * |
||
198 | * @param array $unicode |
||
199 | * @return string |
||
200 | * @since 0.11.0 |
||
201 | * @link http://www.randomchaos.com/documents/?source=php_and_unicode |
||
202 | */ |
||
203 | 1 | private static function unicodeToEntities($unicode) |
|
215 | |||
216 | /** |
||
217 | * Return name without underscore for < 0.10.0 variable name compatibility |
||
218 | * |
||
219 | * @param string $value |
||
220 | * @return string |
||
221 | */ |
||
222 | 1 | public static function removeUnderscorePrefix($value) |
|
232 | } |
||
233 |