1 | <?php |
||
4 | class StringUtils |
||
5 | { |
||
6 | const STRING_REGEXP_FRACTION = '(-?)(\d+)\s+(\d+\/\d+)'; |
||
7 | |||
8 | /** |
||
9 | * Get whether mbstring extension is available |
||
10 | * |
||
11 | * @return boolean |
||
12 | */ |
||
13 | public static function isMbstringEnabled() |
||
17 | |||
18 | /** |
||
19 | * Get whether iconv extension is available |
||
20 | * |
||
21 | * @return boolean |
||
22 | */ |
||
23 | public static function isIconvEnabled() |
||
27 | |||
28 | /** |
||
29 | * @return bool |
||
30 | */ |
||
31 | public static function isMbstringOrIconvEnabled() |
||
35 | |||
36 | /** |
||
37 | * Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length) |
||
38 | * Writes the string using uncompressed notation, no rich text, no Asian phonetics |
||
39 | * If mbstring extension is not available, ASCII is assumed, and compressed notation is used |
||
40 | * although this will give wrong results for non-ASCII strings |
||
41 | * see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3 |
||
42 | * |
||
43 | * @param string $value UTF-8 encoded string |
||
44 | * @return string |
||
45 | */ |
||
46 | public static function toBiff8UnicodeShort($value) |
||
50 | |||
51 | /** |
||
52 | * Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length) |
||
53 | * Writes the string using uncompressed notation, no rich text, no Asian phonetics |
||
54 | * If mbstring extension is not available, ASCII is assumed, and compressed notation is used |
||
55 | * although this will give wrong results for non-ASCII strings |
||
56 | * see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3 |
||
57 | * |
||
58 | * @param string $value UTF-8 encoded string |
||
59 | * @return string |
||
60 | */ |
||
61 | public static function toBiff8UnicodeLong($value) |
||
65 | |||
66 | /** |
||
67 | * @param string $value |
||
68 | * @param int $lengthSize 8 or 16 |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | public static function toBiff8Unicode($value, $lengthSize) |
||
85 | |||
86 | /** |
||
87 | * @param $value |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | public static function toBiff8UnicodeLongWoLenInfo($value) |
||
95 | |||
96 | /** |
||
97 | * Convert string from one encoding to another. First try mbstring, then iconv, finally strlen |
||
98 | * |
||
99 | * @param string $value |
||
100 | * @param string $from Encoding to convert from, e.g. 'UTF-16LE' |
||
101 | * @param string $to Encoding to convert to, e.g. 'UTF-8' |
||
102 | * @return string |
||
103 | */ |
||
104 | public static function convertEncoding($value, $from, $to) |
||
116 | |||
117 | /** |
||
118 | * Get character count. First try mbstring, then iconv, finally strlen |
||
119 | * |
||
120 | * @param string $value |
||
121 | * @param string $enc Encoding |
||
122 | * @return int Character count |
||
123 | */ |
||
124 | public static function countCharacters($value, $enc = 'UTF-8') |
||
137 | |||
138 | /** |
||
139 | * Get a substring of a UTF-8 encoded string. First try mbstring, then iconv, finally strlen |
||
140 | * |
||
141 | * @param string $str UTF-8 encoded string |
||
142 | * @param int $start Start offset |
||
143 | * @param int $length Maximum number of characters in substring |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public static function substr($str = '', $start = 0, $length = 0) |
||
160 | |||
161 | /** |
||
162 | * @param $value |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | public static function toUtf16Le($value) |
||
170 | |||
171 | /** |
||
172 | * @param $str |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | public static function toNullTerminatedWchar($str) |
||
183 | } |
||
184 |