Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like UTF8 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UTF8, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class UTF8 |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | protected static $win1252ToUtf8 = array( |
||
| 20 | 128 => "\xe2\x82\xac", // EURO SIGN |
||
| 21 | 130 => "\xe2\x80\x9a", // SINGLE LOW-9 QUOTATION MARK |
||
| 22 | 131 => "\xc6\x92", // LATIN SMALL LETTER F WITH HOOK |
||
| 23 | 132 => "\xe2\x80\x9e", // DOUBLE LOW-9 QUOTATION MARK |
||
| 24 | 133 => "\xe2\x80\xa6", // HORIZONTAL ELLIPSIS |
||
| 25 | 134 => "\xe2\x80\xa0", // DAGGER |
||
| 26 | 135 => "\xe2\x80\xa1", // DOUBLE DAGGER |
||
| 27 | 136 => "\xcb\x86", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 28 | 137 => "\xe2\x80\xb0", // PER MILLE SIGN |
||
| 29 | 138 => "\xc5\xa0", // LATIN CAPITAL LETTER S WITH CARON |
||
| 30 | 139 => "\xe2\x80\xb9", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 31 | 140 => "\xc5\x92", // LATIN CAPITAL LIGATURE OE |
||
| 32 | 142 => "\xc5\xbd", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 33 | 145 => "\xe2\x80\x98", // LEFT SINGLE QUOTATION MARK |
||
| 34 | 146 => "\xe2\x80\x99", // RIGHT SINGLE QUOTATION MARK |
||
| 35 | 147 => "\xe2\x80\x9c", // LEFT DOUBLE QUOTATION MARK |
||
| 36 | 148 => "\xe2\x80\x9d", // RIGHT DOUBLE QUOTATION MARK |
||
| 37 | 149 => "\xe2\x80\xa2", // BULLET |
||
| 38 | 150 => "\xe2\x80\x93", // EN DASH |
||
| 39 | 151 => "\xe2\x80\x94", // EM DASH |
||
| 40 | 152 => "\xcb\x9c", // SMALL TILDE |
||
| 41 | 153 => "\xe2\x84\xa2", // TRADE MARK SIGN |
||
| 42 | 154 => "\xc5\xa1", // LATIN SMALL LETTER S WITH CARON |
||
| 43 | 155 => "\xe2\x80\xba", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 44 | 156 => "\xc5\x93", // LATIN SMALL LIGATURE OE |
||
| 45 | 158 => "\xc5\xbe", // LATIN SMALL LETTER Z WITH CARON |
||
| 46 | 159 => "\xc5\xb8", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
||
| 47 | ); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var array |
||
| 51 | */ |
||
| 52 | protected static $cp1252ToUtf8 = array( |
||
| 53 | '' => '€', |
||
| 54 | '' => '‚', |
||
| 55 | '' => 'ƒ', |
||
| 56 | '' => '„', |
||
| 57 | ' ' => '…', |
||
| 58 | '' => '†', |
||
| 59 | '' => '‡', |
||
| 60 | '' => 'ˆ', |
||
| 61 | '' => '‰', |
||
| 62 | '' => 'Š', |
||
| 63 | '' => '‹', |
||
| 64 | '' => 'Œ', |
||
| 65 | '' => 'Ž', |
||
| 66 | '' => '‘', |
||
| 67 | '' => '’', |
||
| 68 | '' => '“', |
||
| 69 | '' => '”', |
||
| 70 | '' => '•', |
||
| 71 | '' => '–', |
||
| 72 | '' => '—', |
||
| 73 | '' => '˜', |
||
| 74 | '' => '™', |
||
| 75 | '' => 'š', |
||
| 76 | '' => '›', |
||
| 77 | '' => 'œ', |
||
| 78 | '' => 'ž', |
||
| 79 | '' => 'Ÿ', |
||
| 80 | ); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Numeric code point => UTF-8 Character |
||
| 84 | * |
||
| 85 | * @var array |
||
| 86 | */ |
||
| 87 | protected static $whitespace = array( |
||
| 88 | 0 => "\x0", |
||
| 89 | //NUL Byte |
||
| 90 | 9 => "\x9", |
||
| 91 | //Tab |
||
| 92 | 10 => "\xa", |
||
| 93 | //New Line |
||
| 94 | 11 => "\xb", |
||
| 95 | //Vertical Tab |
||
| 96 | 13 => "\xd", |
||
| 97 | //Carriage Return |
||
| 98 | 32 => "\x20", |
||
| 99 | //Ordinary Space |
||
| 100 | 160 => "\xc2\xa0", |
||
| 101 | //NO-BREAK SPACE |
||
| 102 | 5760 => "\xe1\x9a\x80", |
||
| 103 | //OGHAM SPACE MARK |
||
| 104 | 6158 => "\xe1\xa0\x8e", |
||
| 105 | //MONGOLIAN VOWEL SEPARATOR |
||
| 106 | 8192 => "\xe2\x80\x80", |
||
| 107 | //EN QUAD |
||
| 108 | 8193 => "\xe2\x80\x81", |
||
| 109 | //EM QUAD |
||
| 110 | 8194 => "\xe2\x80\x82", |
||
| 111 | //EN SPACE |
||
| 112 | 8195 => "\xe2\x80\x83", |
||
| 113 | //EM SPACE |
||
| 114 | 8196 => "\xe2\x80\x84", |
||
| 115 | //THREE-PER-EM SPACE |
||
| 116 | 8197 => "\xe2\x80\x85", |
||
| 117 | //FOUR-PER-EM SPACE |
||
| 118 | 8198 => "\xe2\x80\x86", |
||
| 119 | //SIX-PER-EM SPACE |
||
| 120 | 8199 => "\xe2\x80\x87", |
||
| 121 | //FIGURE SPACE |
||
| 122 | 8200 => "\xe2\x80\x88", |
||
| 123 | //PUNCTUATION SPACE |
||
| 124 | 8201 => "\xe2\x80\x89", |
||
| 125 | //THIN SPACE |
||
| 126 | 8202 => "\xe2\x80\x8a", |
||
| 127 | //HAIR SPACE |
||
| 128 | 8232 => "\xe2\x80\xa8", |
||
| 129 | //LINE SEPARATOR |
||
| 130 | 8233 => "\xe2\x80\xa9", |
||
| 131 | //PARAGRAPH SEPARATOR |
||
| 132 | 8239 => "\xe2\x80\xaf", |
||
| 133 | //NARROW NO-BREAK SPACE |
||
| 134 | 8287 => "\xe2\x81\x9f", |
||
| 135 | //MEDIUM MATHEMATICAL SPACE |
||
| 136 | 12288 => "\xe3\x80\x80" |
||
| 137 | //IDEOGRAPHIC SPACE |
||
| 138 | ); |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @var array |
||
| 142 | */ |
||
| 143 | protected static $whitespaceTable = array( |
||
| 144 | 'SPACE' => "\x20", |
||
| 145 | 'NO-BREAK SPACE' => "\xc2\xa0", |
||
| 146 | 'OGHAM SPACE MARK' => "\xe1\x9a\x80", |
||
| 147 | 'EN QUAD' => "\xe2\x80\x80", |
||
| 148 | 'EM QUAD' => "\xe2\x80\x81", |
||
| 149 | 'EN SPACE' => "\xe2\x80\x82", |
||
| 150 | 'EM SPACE' => "\xe2\x80\x83", |
||
| 151 | 'THREE-PER-EM SPACE' => "\xe2\x80\x84", |
||
| 152 | 'FOUR-PER-EM SPACE' => "\xe2\x80\x85", |
||
| 153 | 'SIX-PER-EM SPACE' => "\xe2\x80\x86", |
||
| 154 | 'FIGURE SPACE' => "\xe2\x80\x87", |
||
| 155 | 'PUNCTUATION SPACE' => "\xe2\x80\x88", |
||
| 156 | 'THIN SPACE' => "\xe2\x80\x89", |
||
| 157 | 'HAIR SPACE' => "\xe2\x80\x8a", |
||
| 158 | 'ZERO WIDTH SPACE' => "\xe2\x80\x8b", |
||
| 159 | 'NARROW NO-BREAK SPACE' => "\xe2\x80\xaf", |
||
| 160 | 'MEDIUM MATHEMATICAL SPACE' => "\xe2\x81\x9f", |
||
| 161 | 'IDEOGRAPHIC SPACE' => "\xe3\x80\x80", |
||
| 162 | ); |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var array |
||
| 166 | */ |
||
| 167 | protected static $commonCaseFold = array( |
||
| 168 | 'ſ' => 's', |
||
| 169 | "\xCD\x85" => 'ι', |
||
| 170 | 'ς' => 'σ', |
||
| 171 | "\xCF\x90" => 'β', |
||
| 172 | "\xCF\x91" => 'θ', |
||
| 173 | "\xCF\x95" => 'φ', |
||
| 174 | "\xCF\x96" => 'π', |
||
| 175 | "\xCF\xB0" => 'κ', |
||
| 176 | "\xCF\xB1" => 'ρ', |
||
| 177 | "\xCF\xB5" => 'ε', |
||
| 178 | "\xE1\xBA\x9B" => "\xE1\xB9\xA1", |
||
| 179 | "\xE1\xBE\xBE" => 'ι', |
||
| 180 | ); |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @var array |
||
| 184 | */ |
||
| 185 | protected static $brokenUtf8ToUtf8 = array( |
||
| 186 | "\xc2\x80" => "\xe2\x82\xac", // EURO SIGN |
||
| 187 | "\xc2\x82" => "\xe2\x80\x9a", // SINGLE LOW-9 QUOTATION MARK |
||
| 188 | "\xc2\x83" => "\xc6\x92", // LATIN SMALL LETTER F WITH HOOK |
||
| 189 | "\xc2\x84" => "\xe2\x80\x9e", // DOUBLE LOW-9 QUOTATION MARK |
||
| 190 | "\xc2\x85" => "\xe2\x80\xa6", // HORIZONTAL ELLIPSIS |
||
| 191 | "\xc2\x86" => "\xe2\x80\xa0", // DAGGER |
||
| 192 | "\xc2\x87" => "\xe2\x80\xa1", // DOUBLE DAGGER |
||
| 193 | "\xc2\x88" => "\xcb\x86", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 194 | "\xc2\x89" => "\xe2\x80\xb0", // PER MILLE SIGN |
||
| 195 | "\xc2\x8a" => "\xc5\xa0", // LATIN CAPITAL LETTER S WITH CARON |
||
| 196 | "\xc2\x8b" => "\xe2\x80\xb9", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 197 | "\xc2\x8c" => "\xc5\x92", // LATIN CAPITAL LIGATURE OE |
||
| 198 | "\xc2\x8e" => "\xc5\xbd", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 199 | "\xc2\x91" => "\xe2\x80\x98", // LEFT SINGLE QUOTATION MARK |
||
| 200 | "\xc2\x92" => "\xe2\x80\x99", // RIGHT SINGLE QUOTATION MARK |
||
| 201 | "\xc2\x93" => "\xe2\x80\x9c", // LEFT DOUBLE QUOTATION MARK |
||
| 202 | "\xc2\x94" => "\xe2\x80\x9d", // RIGHT DOUBLE QUOTATION MARK |
||
| 203 | "\xc2\x95" => "\xe2\x80\xa2", // BULLET |
||
| 204 | "\xc2\x96" => "\xe2\x80\x93", // EN DASH |
||
| 205 | "\xc2\x97" => "\xe2\x80\x94", // EM DASH |
||
| 206 | "\xc2\x98" => "\xcb\x9c", // SMALL TILDE |
||
| 207 | "\xc2\x99" => "\xe2\x84\xa2", // TRADE MARK SIGN |
||
| 208 | "\xc2\x9a" => "\xc5\xa1", // LATIN SMALL LETTER S WITH CARON |
||
| 209 | "\xc2\x9b" => "\xe2\x80\xba", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 210 | "\xc2\x9c" => "\xc5\x93", // LATIN SMALL LIGATURE OE |
||
| 211 | "\xc2\x9e" => "\xc5\xbe", // LATIN SMALL LETTER Z WITH CARON |
||
| 212 | "\xc2\x9f" => "\xc5\xb8", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
||
| 213 | 'ü' => 'ü', |
||
| 214 | 'ä' => 'ä', |
||
| 215 | 'ö' => 'ö', |
||
| 216 | 'Ö' => 'Ö', |
||
| 217 | 'ß' => 'ß', |
||
| 218 | 'Ã ' => 'à', |
||
| 219 | 'á' => 'á', |
||
| 220 | 'â' => 'â', |
||
| 221 | 'ã' => 'ã', |
||
| 222 | 'ù' => 'ù', |
||
| 223 | 'ú' => 'ú', |
||
| 224 | 'û' => 'û', |
||
| 225 | 'Ù' => 'Ù', |
||
| 226 | 'Ú' => 'Ú', |
||
| 227 | 'Û' => 'Û', |
||
| 228 | 'Ü' => 'Ü', |
||
| 229 | 'ò' => 'ò', |
||
| 230 | 'ó' => 'ó', |
||
| 231 | 'ô' => 'ô', |
||
| 232 | 'è' => 'è', |
||
| 233 | 'é' => 'é', |
||
| 234 | 'ê' => 'ê', |
||
| 235 | 'ë' => 'ë', |
||
| 236 | 'À' => 'À', |
||
| 237 | 'Ã' => 'Á', |
||
| 238 | 'Â' => 'Â', |
||
| 239 | 'Ã' => 'Ã', |
||
| 240 | 'Ä' => 'Ä', |
||
| 241 | 'Ã…' => 'Å', |
||
| 242 | 'Ç' => 'Ç', |
||
| 243 | 'È' => 'È', |
||
| 244 | 'É' => 'É', |
||
| 245 | 'Ê' => 'Ê', |
||
| 246 | 'Ë' => 'Ë', |
||
| 247 | 'ÃŒ' => 'Ì', |
||
| 248 | 'Ã' => 'Í', |
||
| 249 | 'ÃŽ' => 'Î', |
||
| 250 | 'Ã' => 'Ï', |
||
| 251 | 'Ñ' => 'Ñ', |
||
| 252 | 'Ã’' => 'Ò', |
||
| 253 | 'Ó' => 'Ó', |
||
| 254 | 'Ô' => 'Ô', |
||
| 255 | 'Õ' => 'Õ', |
||
| 256 | 'Ø' => 'Ø', |
||
| 257 | 'Ã¥' => 'å', |
||
| 258 | 'æ' => 'æ', |
||
| 259 | 'ç' => 'ç', |
||
| 260 | 'ì' => 'ì', |
||
| 261 | 'Ã' => 'í', |
||
| 262 | 'î' => 'î', |
||
| 263 | 'ï' => 'ï', |
||
| 264 | 'ð' => 'ð', |
||
| 265 | 'ñ' => 'ñ', |
||
| 266 | 'õ' => 'õ', |
||
| 267 | 'ø' => 'ø', |
||
| 268 | 'ý' => 'ý', |
||
| 269 | 'ÿ' => 'ÿ', |
||
| 270 | '€' => '€', |
||
| 271 | ); |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @var array |
||
| 275 | */ |
||
| 276 | protected static $utf8ToWin1252 = array( |
||
| 277 | "\xe2\x82\xac" => "\x80", // EURO SIGN |
||
| 278 | "\xe2\x80\x9a" => "\x82", // SINGLE LOW-9 QUOTATION MARK |
||
| 279 | "\xc6\x92" => "\x83", // LATIN SMALL LETTER F WITH HOOK |
||
| 280 | "\xe2\x80\x9e" => "\x84", // DOUBLE LOW-9 QUOTATION MARK |
||
| 281 | "\xe2\x80\xa6" => "\x85", // HORIZONTAL ELLIPSIS |
||
| 282 | "\xe2\x80\xa0" => "\x86", // DAGGER |
||
| 283 | "\xe2\x80\xa1" => "\x87", // DOUBLE DAGGER |
||
| 284 | "\xcb\x86" => "\x88", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 285 | "\xe2\x80\xb0" => "\x89", // PER MILLE SIGN |
||
| 286 | "\xc5\xa0" => "\x8a", // LATIN CAPITAL LETTER S WITH CARON |
||
| 287 | "\xe2\x80\xb9" => "\x8b", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 288 | "\xc5\x92" => "\x8c", // LATIN CAPITAL LIGATURE OE |
||
| 289 | "\xc5\xbd" => "\x8e", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 290 | "\xe2\x80\x98" => "\x91", // LEFT SINGLE QUOTATION MARK |
||
| 291 | "\xe2\x80\x99" => "\x92", // RIGHT SINGLE QUOTATION MARK |
||
| 292 | "\xe2\x80\x9c" => "\x93", // LEFT DOUBLE QUOTATION MARK |
||
| 293 | "\xe2\x80\x9d" => "\x94", // RIGHT DOUBLE QUOTATION MARK |
||
| 294 | "\xe2\x80\xa2" => "\x95", // BULLET |
||
| 295 | "\xe2\x80\x93" => "\x96", // EN DASH |
||
| 296 | "\xe2\x80\x94" => "\x97", // EM DASH |
||
| 297 | "\xcb\x9c" => "\x98", // SMALL TILDE |
||
| 298 | "\xe2\x84\xa2" => "\x99", // TRADE MARK SIGN |
||
| 299 | "\xc5\xa1" => "\x9a", // LATIN SMALL LETTER S WITH CARON |
||
| 300 | "\xe2\x80\xba" => "\x9b", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 301 | "\xc5\x93" => "\x9c", // LATIN SMALL LIGATURE OE |
||
| 302 | "\xc5\xbe" => "\x9e", // LATIN SMALL LETTER Z WITH CARON |
||
| 303 | "\xc5\xb8" => "\x9f", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
||
| 304 | ); |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @var array |
||
| 308 | */ |
||
| 309 | protected static $utf8MSWord = array( |
||
| 310 | "\xc2\xab" => '"', // « (U+00AB) in UTF-8 |
||
| 311 | "\xc2\xbb" => '"', // » (U+00BB) in UTF-8 |
||
| 312 | "\xe2\x80\x98" => "'", // ‘ (U+2018) in UTF-8 |
||
| 313 | "\xe2\x80\x99" => "'", // ’ (U+2019) in UTF-8 |
||
| 314 | "\xe2\x80\x9a" => "'", // ‚ (U+201A) in UTF-8 |
||
| 315 | "\xe2\x80\x9b" => "'", // ‛ (U+201B) in UTF-8 |
||
| 316 | "\xe2\x80\x9c" => '"', // “ (U+201C) in UTF-8 |
||
| 317 | "\xe2\x80\x9d" => '"', // ” (U+201D) in UTF-8 |
||
| 318 | "\xe2\x80\x9e" => '"', // „ (U+201E) in UTF-8 |
||
| 319 | "\xe2\x80\x9f" => '"', // ‟ (U+201F) in UTF-8 |
||
| 320 | "\xe2\x80\xb9" => "'", // ‹ (U+2039) in UTF-8 |
||
| 321 | "\xe2\x80\xba" => "'", // › (U+203A) in UTF-8 |
||
| 322 | "\xe2\x80\x93" => '-', // – (U+2013) in UTF-8 |
||
| 323 | "\xe2\x80\x94" => '-', // — (U+2014) in UTF-8 |
||
| 324 | "\xe2\x80\xa6" => '...' // … (U+2026) in UTF-8 |
||
| 325 | ); |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @var array |
||
| 329 | */ |
||
| 330 | private static $support = array(); |
||
| 331 | |||
| 332 | /** |
||
| 333 | * __construct() |
||
| 334 | */ |
||
| 335 | 1 | public function __construct() |
|
| 339 | |||
| 340 | /** |
||
| 341 | * Returns a single UTF-8 character from string. |
||
| 342 | * |
||
| 343 | 151 | * @param string $str A UTF-8 string. |
|
| 344 | * @param int $pos The position of character to return. |
||
| 345 | 151 | * |
|
| 346 | * @return string Single Multi-Byte character. |
||
| 347 | 1 | */ |
|
| 348 | 1 | public static function access($str, $pos) |
|
| 354 | 1 | ||
| 355 | 1 | /** |
|
| 356 | 151 | * Prepends BOM character to the string and returns the whole string. |
|
| 357 | * |
||
| 358 | * INFO: If BOM already existed there, the Input string is returned. |
||
| 359 | * |
||
| 360 | * @param string $str The input string |
||
| 361 | * |
||
| 362 | * @return string The output string that contains BOM |
||
| 363 | 2 | */ |
|
| 364 | public static function add_bom_to_string($str) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Returns the Byte Order Mark Character. |
||
| 375 | * |
||
| 376 | * @return string Byte Order Mark |
||
| 377 | */ |
||
| 378 | public static function bom() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @alias of UTF8::chr_map() |
||
| 385 | * |
||
| 386 | * @param $callback |
||
| 387 | * @param $str |
||
| 388 | * |
||
| 389 | 1 | * @return array |
|
| 390 | */ |
||
| 391 | 1 | public static function callback($callback, $str) |
|
| 395 | |||
| 396 | /** |
||
| 397 | * Returns an array of all lower and upper case UTF-8 encoded characters. |
||
| 398 | * |
||
| 399 | 30 | * @return string An array with lower case chars as keys and upper chars as values. |
|
| 400 | */ |
||
| 401 | protected static function case_table() |
||
| 1402 | |||
| 1403 | /** |
||
| 1404 | * check for UTF8-Support |
||
| 1405 | */ |
||
| 1406 | public static function checkForSupport() |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * Generates a UTF-8 encoded character from the given code point. |
||
| 1419 | 23 | * |
|
| 1420 | * @param int $code_point The code point for which to generate a character. |
||
| 1421 | * |
||
| 1422 | * @return string Multi-Byte character, returns empty string on failure to encode. |
||
| 1423 | */ |
||
| 1424 | public static function chr($code_point) |
||
| 1437 | 30 | ||
| 1438 | /** |
||
| 1439 | * Applies callback to all characters of a string. |
||
| 1440 | 16 | * |
|
| 1441 | * @param string $callback The callback function. |
||
| 1442 | 16 | * @param string $str UTF-8 string to run callback on. |
|
| 1443 | 15 | * |
|
| 1444 | * @return array The outcome of callback. |
||
| 1445 | 15 | */ |
|
| 1446 | 14 | ||
| 1447 | 15 | public static function chr_map($callback, $str) |
|
| 1453 | |||
| 1454 | 16 | /** |
|
| 1455 | * Generates an array of byte length of each character of a Unicode string. |
||
| 1456 | 16 | * |
|
| 1457 | 16 | * 1 byte => U+0000 - U+007F |
|
| 1458 | 16 | * 2 byte => U+0080 - U+07FF |
|
| 1459 | * 3 byte => U+0800 - U+FFFF |
||
| 1460 | * 4 byte => U+10000 - U+10FFFF |
||
| 1461 | * |
||
| 1462 | 16 | * @param string $str The original Unicode string. |
|
| 1463 | * |
||
| 1464 | 16 | * @return array An array of byte lengths of each character. |
|
| 1465 | */ |
||
| 1466 | public static function chr_size_list($str) |
||
| 1474 | |||
| 1475 | 17 | /** |
|
| 1476 | * Get a decimal code representation of a specific character. |
||
| 1477 | * |
||
| 1478 | 17 | * @param string $chr The input character |
|
| 1479 | * |
||
| 1480 | 17 | * @return int |
|
| 1481 | */ |
||
| 1482 | public static function chr_to_decimal($chr) |
||
| 1514 | 1 | ||
| 1515 | /** |
||
| 1516 | * Get hexadecimal code point (U+xxxx) of a UTF-8 encoded character. |
||
| 1517 | * |
||
| 1518 | * @param string $chr The input character |
||
| 1519 | * @param string $pfix |
||
| 1520 | * |
||
| 1521 | * @return string The code point encoded as U+xxxx |
||
| 1522 | */ |
||
| 1523 | public static function chr_to_hex($chr, $pfix = 'U+') |
||
| 1527 | 1 | ||
| 1528 | /** |
||
| 1529 | 1 | * Splits a string into smaller chunks and multiple lines, using the specified |
|
| 1530 | * line ending character. |
||
| 1531 | * |
||
| 1532 | * @param string $body The original string to be split. |
||
| 1533 | * @param int $chunklen The maximum character length of a chunk. |
||
| 1534 | * @param string $end The character(s) to be inserted at the end of each chunk. |
||
| 1535 | * |
||
| 1536 | * @return string The chunked string |
||
| 1537 | */ |
||
| 1538 | public static function chunk_split($body, $chunklen = 76, $end = "\r\n") |
||
| 1542 | 5 | ||
| 1543 | /** |
||
| 1544 | 5 | * accepts a string and removes all non-UTF-8 characters from it. |
|
| 1545 | * |
||
| 1546 | * @param string $str The string to be sanitized. |
||
| 1547 | * @param bool $remove_bom |
||
| 1548 | 5 | * @param bool $normalize_whitespace |
|
| 1549 | * @param bool $normalize_msword e.g.: "…" => "..." |
||
| 1550 | * @param bool $keep_non_breaking_space set true, to keep non-breaking-spaces |
||
| 1551 | 5 | * |
|
| 1552 | * @return string Clean UTF-8 encoded string |
||
| 1553 | */ |
||
| 1554 | public static function clean($str, $remove_bom = false, $normalize_whitespace = false, $normalize_msword = false, $keep_non_breaking_space = false) |
||
| 1590 | |||
| 1591 | /** |
||
| 1592 | * Clean-up a and show only printable UTF-8 chars at the end. |
||
| 1593 | 5 | * |
|
| 1594 | * @param string|false $str |
||
| 1595 | 5 | * |
|
| 1596 | * @return string |
||
| 1597 | */ |
||
| 1598 | public static function cleanup($str) |
||
| 1621 | 2 | ||
| 1622 | /** |
||
| 1623 | 2 | * Accepts a string and returns an array of Unicode code points. |
|
| 1624 | * |
||
| 1625 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
||
| 1626 | * @param bool $u_style If True, will return code points in U+xxxx format, |
||
| 1627 | * default, code points will be returned as integers. |
||
| 1628 | * |
||
| 1629 | * @return array The array of code points |
||
| 1630 | */ |
||
| 1631 | public static function codepoints($arg, $u_style = false) |
||
| 1657 | 1 | ||
| 1658 | /** |
||
| 1659 | 10 | * Returns count of characters used in a string. |
|
| 1660 | * |
||
| 1661 | 10 | * @param string $str The input string. |
|
| 1662 | * |
||
| 1663 | 10 | * @return array An associative array of Character as keys and |
|
| 1664 | 1 | * their count as values. |
|
| 1665 | 1 | */ |
|
| 1666 | public static function count_chars($str) // there is no $mode parameters |
||
| 1674 | |||
| 1675 | /** |
||
| 1676 | * Get a UTF-8 character from its decimal code representation. |
||
| 1677 | * |
||
| 1678 | * @param int $code Code. |
||
| 1679 | * |
||
| 1680 | * @return string |
||
| 1681 | */ |
||
| 1682 | public static function decimal_to_chr($code) |
||
| 1692 | 5 | ||
| 1693 | /** |
||
| 1694 | * Encode to UTF8 or LATIN1. |
||
| 1695 | * |
||
| 1696 | 17 | * INFO: The different to "UTF8::utf8_encode()" is that this function, try to fix also broken / double encoding, |
|
| 1697 | * so you can call this function also on a UTF-8 String and you don't mess the string. |
||
| 1698 | 17 | * |
|
| 1699 | * @param string $encodingLabel ISO-8859-1 || UTF-8 |
||
| 1700 | * @param string $str |
||
| 1701 | * |
||
| 1702 | * @return false|string Will return false on error. |
||
| 1703 | */ |
||
| 1704 | public static function encode($encodingLabel, $str) |
||
| 1718 | 1 | ||
| 1719 | /** |
||
| 1720 | 1 | * Reads entire file into a string. |
|
| 1721 | * |
||
| 1722 | 1 | * WARNING: do not use UTF-8 Option fir binary-files (e.g.: images) !!! |
|
| 1723 | 1 | * |
|
| 1724 | 1 | * @link http://php.net/manual/en/function.file-get-contents.php |
|
| 1725 | 1 | * |
|
| 1726 | * @param string $filename <p> |
||
| 1727 | 1 | * Name of the file to read. |
|
| 1728 | 1 | * </p> |
|
| 1729 | 1 | * @param int $flags [optional] <p> |
|
| 1730 | * Prior to PHP 6, this parameter is called |
||
| 1731 | 1 | * use_include_path and is a bool. |
|
| 1732 | * As of PHP 5 the FILE_USE_INCLUDE_PATH can be used |
||
| 1733 | * to trigger include path |
||
| 1734 | * search. |
||
| 1735 | * </p> |
||
| 1736 | * <p> |
||
| 1737 | * The value of flags can be any combination of |
||
| 1738 | * the following flags (with some restrictions), joined with the |
||
| 1739 | * binary OR (|) |
||
| 1740 | * operator. |
||
| 1741 | 8 | * </p> |
|
| 1742 | * <p> |
||
| 1743 | 8 | * <table> |
|
| 1744 | 8 | * Available flags |
|
| 1745 | * <tr valign="top"> |
||
| 1746 | 8 | * <td>Flag</td> |
|
| 1747 | * <td>Description</td> |
||
| 1748 | 8 | * </tr> |
|
| 1749 | 2 | * <tr valign="top"> |
|
| 1750 | * <td> |
||
| 1751 | * FILE_USE_INCLUDE_PATH |
||
| 1752 | 8 | * </td> |
|
| 1753 | 1 | * <td> |
|
| 1754 | 1 | * Search for filename in the include directory. |
|
| 1755 | 1 | * See include_path for more |
|
| 1756 | * information. |
||
| 1757 | 8 | * </td> |
|
| 1758 | * </tr> |
||
| 1759 | * <tr valign="top"> |
||
| 1760 | * <td> |
||
| 1761 | * FILE_TEXT |
||
| 1762 | * </td> |
||
| 1763 | * <td> |
||
| 1764 | * As of PHP 6, the default encoding of the read |
||
| 1765 | * data is UTF-8. You can specify a different encoding by creating a |
||
| 1766 | * custom context or by changing the default using |
||
| 1767 | * stream_default_encoding. This flag cannot be |
||
| 1768 | * used with FILE_BINARY. |
||
| 1769 | * </td> |
||
| 1770 | * </tr> |
||
| 1771 | * <tr valign="top"> |
||
| 1772 | * <td> |
||
| 1773 | * FILE_BINARY |
||
| 1774 | * </td> |
||
| 1775 | * <td> |
||
| 1776 | * With this flag, the file is read in binary mode. This is the default |
||
| 1777 | * setting and cannot be used with FILE_TEXT. |
||
| 1778 | * </td> |
||
| 1779 | * </tr> |
||
| 1780 | * </table> |
||
| 1781 | * </p> |
||
| 1782 | * @param resource $context [optional] <p> |
||
| 1783 | * A valid context resource created with |
||
| 1784 | * stream_context_create. If you don't need to use a |
||
| 1785 | * custom context, you can skip this parameter by &null;. |
||
| 1786 | * </p> |
||
| 1787 | * @param int $offset [optional] <p> |
||
| 1788 | * The offset where the reading starts. |
||
| 1789 | * </p> |
||
| 1790 | * @param int $maxlen [optional] <p> |
||
| 1791 | * Maximum length of data read. The default is to read until end |
||
| 1792 | * of file is reached. |
||
| 1793 | * </p> |
||
| 1794 | * @param int $timeout |
||
| 1795 | * |
||
| 1796 | * @param boolean $convertToUtf8 WARNING: maybe you can't use this option for images or pdf, because they used non |
||
| 1797 | * default utf-8 chars |
||
| 1798 | * |
||
| 1799 | * @return string The function returns the read data or false on failure. |
||
| 1800 | */ |
||
| 1801 | public static function file_get_contents($filename, $flags = null, $context = null, $offset = null, $maxlen = null, $timeout = 10, $convertToUtf8 = true) |
||
| 1848 | 2 | ||
| 1849 | /** |
||
| 1850 | * Checks if a file starts with BOM character. |
||
| 1851 | 14 | * |
|
| 1852 | * @param string $file_path Path to a valid file. |
||
| 1853 | * |
||
| 1854 | 14 | * @return bool True if the file has BOM at the start, False otherwise. |
|
| 1855 | 14 | */ |
|
| 1856 | 14 | public static function file_has_bom($file_path) |
|
| 1860 | |||
| 1861 | 14 | /** |
|
| 1862 | * Normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
||
| 1863 | * |
||
| 1864 | * @param mixed $var |
||
| 1865 | * @param int $normalization_form |
||
| 1866 | * @param string $leading_combining |
||
| 1867 | * |
||
| 1868 | * @return mixed |
||
| 1869 | */ |
||
| 1870 | public static function filter($var, $normalization_form = 4, $leading_combining = '◌') |
||
| 1913 | 20 | ||
| 1914 | 20 | /** |
|
| 1915 | 20 | * "filter_input()"-wrapper with normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
|
| 1916 | 20 | * |
|
| 1917 | * @param int $type |
||
| 1918 | 20 | * @param string $var |
|
| 1919 | * @param int $filter |
||
| 1920 | 18 | * @param mixed $option |
|
| 1921 | 17 | * |
|
| 1922 | 17 | * @return mixed |
|
| 1923 | 17 | */ |
|
| 1924 | 5 | View Code Duplication | public static function filter_input($type, $var, $filter = FILTER_DEFAULT, $option = null) |
| 1934 | 14 | ||
| 1935 | 8 | /** |
|
| 1936 | 8 | * "filter_input_array()"-wrapper with normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
|
| 1937 | 8 | * |
|
| 1938 | * @param int $type |
||
| 1939 | * @param mixed $definition |
||
| 1940 | 19 | * @param bool $add_empty |
|
| 1941 | * |
||
| 1942 | 7 | * @return mixed |
|
| 1943 | 1 | */ |
|
| 1944 | 1 | View Code Duplication | public static function filter_input_array($type, $definition = null, $add_empty = true) |
| 1954 | 6 | ||
| 1955 | /** |
||
| 1956 | * "filter_var()"-wrapper with normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
||
| 1957 | 20 | * |
|
| 1958 | * @param mixed $var |
||
| 1959 | 2 | * @param int $filter |
|
| 1960 | 2 | * @param mixed $option |
|
| 1961 | * |
||
| 1962 | * @return mixed |
||
| 1963 | 2 | */ |
|
| 1964 | 2 | View Code Duplication | public static function filter_var($var, $filter = FILTER_DEFAULT, $option = null) |
| 1974 | |||
| 1975 | /** |
||
| 1976 | 20 | * "filter_var_array()"-wrapper with normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
|
| 1977 | 20 | * |
|
| 1978 | * @param array $data |
||
| 1979 | 3 | * @param mixed $definition |
|
| 1980 | 20 | * @param bool $add_empty |
|
| 1981 | * |
||
| 1982 | 20 | * @return mixed |
|
| 1983 | */ |
||
| 1984 | View Code Duplication | public static function filter_var_array($data, $definition = null, $add_empty = true) |
|
| 1994 | |||
| 1995 | /** |
||
| 1996 | * Checks if the number of Unicode characters in a string are not |
||
| 1997 | * more than the specified integer. |
||
| 1998 | * |
||
| 1999 | * @param string $str The original string to be checked. |
||
| 2000 | * @param int $box_size The size in number of chars to be checked against string. |
||
| 2001 | * |
||
| 2002 | * @return bool true if string is less than or equal to $box_size, false otherwise. |
||
| 2003 | */ |
||
| 2004 | public static function fits_inside($str, $box_size) |
||
| 2008 | |||
| 2009 | /** |
||
| 2010 | * Fixing a broken UTF-8 string. |
||
| 2011 | * |
||
| 2012 | * @param string $str |
||
| 2013 | * |
||
| 2014 | * @return string |
||
| 2015 | */ |
||
| 2016 | public static function fix_simple_utf8($str) |
||
| 2034 | |||
| 2035 | /** |
||
| 2036 | * Fix a double (or multiple) encoded UTF8 string. |
||
| 2037 | * |
||
| 2038 | * @param array|string $str |
||
| 2039 | * |
||
| 2040 | * @return string |
||
| 2041 | */ |
||
| 2042 | public static function fix_utf8($str) |
||
| 2062 | |||
| 2063 | /** |
||
| 2064 | * Get character of a specific character. |
||
| 2065 | * |
||
| 2066 | * @param string $chr Character. |
||
| 2067 | * |
||
| 2068 | * @return string 'RTL' or 'LTR' |
||
| 2069 | */ |
||
| 2070 | public static function getCharDirection($chr) |
||
| 2162 | |||
| 2163 | /** |
||
| 2164 | * get data from "/data/*.ser" |
||
| 2165 | 2 | * |
|
| 2166 | * @param string $file |
||
| 2167 | * |
||
| 2168 | * @return bool|string|array|int false on error |
||
| 2169 | 2 | */ |
|
| 2170 | 2 | protected static function getData($file) |
|
| 2179 | |||
| 2180 | /** |
||
| 2181 | 2 | * Creates a random string of UTF-8 characters. |
|
| 2182 | * |
||
| 2183 | * @param int $len The length of string in characters. |
||
| 2184 | * |
||
| 2185 | * @return string String consisting of random characters. |
||
| 2186 | */ |
||
| 2187 | public static function hash($len = 8) |
||
| 2227 | 2 | ||
| 2228 | /** |
||
| 2229 | * Converts hexadecimal U+xxxx code point representation to Integer. |
||
| 2230 | * |
||
| 2231 | 2 | * INFO: opposite to UTF8::int_to_hex( ) |
|
| 2232 | 2 | * |
|
| 2233 | 2 | * @param string $str The hexadecimal code point representation. |
|
| 2234 | 2 | * |
|
| 2235 | 2 | * @return int The code point, or 0 on failure. |
|
| 2236 | 2 | */ |
|
| 2237 | public static function hex_to_int($str) |
||
| 2245 | 1 | ||
| 2246 | /** |
||
| 2247 | * Converts a UTF-8 string to a series of HTML numbered entities. |
||
| 2248 | 1 | * |
|
| 2249 | * e.g.: {'ی |
||
| 2250 | 2 | * |
|
| 2251 | * @param string $str The Unicode string to be encoded as numbered entities. |
||
| 2252 | * |
||
| 2253 | * @return string HTML numbered entities. |
||
| 2254 | 2 | */ |
|
| 2255 | public static function html_encode($str) |
||
| 2267 | 3 | ||
| 2268 | /** |
||
| 2269 | * UTF-8 version of html_entity_decode() |
||
| 2270 | 3 | * |
|
| 2271 | * The reason we are not using html_entity_decode() by itself is because |
||
| 2272 | 3 | * while it is not technically correct to leave out the semicolon |
|
| 2273 | 3 | * at the end of an entity most browsers will still interpret the entity |
|
| 2274 | 3 | * correctly. html_entity_decode() does not convert entities without |
|
| 2275 | 3 | * semicolons, so we are left with our own little solution here. Bummer. |
|
| 2276 | 2 | * |
|
| 2277 | * Convert all HTML entities to their applicable characters |
||
| 2278 | 3 | * |
|
| 2279 | * @link http://php.net/manual/en/function.html-entity-decode.php |
||
| 2280 | * |
||
| 2281 | * @param string $str <p> |
||
| 2282 | * The input string. |
||
| 2283 | * </p> |
||
| 2284 | * @param int $flags [optional] <p> |
||
| 2285 | * A bitmask of one or more of the following flags, which specify how to handle quotes and |
||
| 2286 | * which document type to use. The default is ENT_COMPAT | ENT_HTML401. |
||
| 2287 | * <table> |
||
| 2288 | * Available <i>flags</i> constants |
||
| 2289 | 1 | * <tr valign="top"> |
|
| 2290 | * <td>Constant Name</td> |
||
| 2291 | 1 | * <td>Description</td> |
|
| 2292 | 1 | * </tr> |
|
| 2293 | * <tr valign="top"> |
||
| 2294 | 1 | * <td><b>ENT_COMPAT</b></td> |
|
| 2295 | 1 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
|
| 2296 | 1 | * </tr> |
|
| 2297 | 1 | * <tr valign="top"> |
|
| 2298 | 1 | * <td><b>ENT_QUOTES</b></td> |
|
| 2299 | 1 | * <td>Will convert both double and single quotes.</td> |
|
| 2300 | 1 | * </tr> |
|
| 2301 | 1 | * <tr valign="top"> |
|
| 2302 | 1 | * <td><b>ENT_NOQUOTES</b></td> |
|
| 2303 | 1 | * <td>Will leave both double and single quotes unconverted.</td> |
|
| 2304 | 1 | * </tr> |
|
| 2305 | 1 | * <tr valign="top"> |
|
| 2306 | 1 | * <td><b>ENT_HTML401</b></td> |
|
| 2307 | 1 | * <td> |
|
| 2308 | * Handle code as HTML 4.01. |
||
| 2309 | 1 | * </td> |
|
| 2310 | 1 | * </tr> |
|
| 2311 | 1 | * <tr valign="top"> |
|
| 2312 | 1 | * <td><b>ENT_XML1</b></td> |
|
| 2313 | 1 | * <td> |
|
| 2314 | 1 | * Handle code as XML 1. |
|
| 2315 | 1 | * </td> |
|
| 2316 | 1 | * </tr> |
|
| 2317 | 1 | * <tr valign="top"> |
|
| 2318 | 1 | * <td><b>ENT_XHTML</b></td> |
|
| 2319 | 1 | * <td> |
|
| 2320 | 1 | * Handle code as XHTML. |
|
| 2321 | 1 | * </td> |
|
| 2322 | 1 | * </tr> |
|
| 2323 | * <tr valign="top"> |
||
| 2324 | 1 | * <td><b>ENT_HTML5</b></td> |
|
| 2325 | 1 | * <td> |
|
| 2326 | 1 | * Handle code as HTML 5. |
|
| 2327 | * </td> |
||
| 2328 | 1 | * </tr> |
|
| 2329 | * </table> |
||
| 2330 | * </p> |
||
| 2331 | * @param string $encoding [optional] <p> |
||
| 2332 | 1 | * Encoding to use. |
|
| 2333 | * </p> |
||
| 2334 | 1 | * |
|
| 2335 | * @return string the decoded string. |
||
| 2336 | */ |
||
| 2337 | public static function html_entity_decode($str, $flags = null, $encoding = 'UTF-8') |
||
| 2373 | 1 | ||
| 2374 | 1 | /** |
|
| 2375 | * Callback function for preg_replace_callback use. |
||
| 2376 | * |
||
| 2377 | 1 | * @param array $matches PREG matches |
|
| 2378 | 1 | * |
|
| 2379 | 1 | * @return string |
|
| 2380 | */ |
||
| 2381 | 1 | protected static function entityCallback(&$matches) |
|
| 2393 | |||
| 2394 | /** |
||
| 2395 | * Convert all applicable characters to HTML entities: UTF-8 version of htmlentities() |
||
| 2396 | 1 | * |
|
| 2397 | * @link http://php.net/manual/en/function.htmlentities.php |
||
| 2398 | * |
||
| 2399 | * @param string $str <p> |
||
| 2400 | * The input string. |
||
| 2401 | * </p> |
||
| 2402 | * @param int $flags [optional] <p> |
||
| 2403 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
||
| 2404 | 1 | * invalid code unit sequences and the used document type. The default is |
|
| 2405 | * ENT_COMPAT | ENT_HTML401. |
||
| 2406 | 1 | * <table> |
|
| 2407 | * Available <i>flags</i> constants |
||
| 2408 | * <tr valign="top"> |
||
| 2409 | * <td>Constant Name</td> |
||
| 2410 | * <td>Description</td> |
||
| 2411 | * </tr> |
||
| 2412 | * <tr valign="top"> |
||
| 2413 | * <td><b>ENT_COMPAT</b></td> |
||
| 2414 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 2415 | * </tr> |
||
| 2416 | 5 | * <tr valign="top"> |
|
| 2417 | * <td><b>ENT_QUOTES</b></td> |
||
| 2418 | 5 | * <td>Will convert both double and single quotes.</td> |
|
| 2419 | * </tr> |
||
| 2420 | 5 | * <tr valign="top"> |
|
| 2421 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 2422 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 2423 | * </tr> |
||
| 2424 | * <tr valign="top"> |
||
| 2425 | 5 | * <td><b>ENT_IGNORE</b></td> |
|
| 2426 | * <td> |
||
| 2427 | * Silently discard invalid code unit sequences instead of returning |
||
| 2428 | 5 | * an empty string. Using this flag is discouraged as it |
|
| 2429 | * may have security implications. |
||
| 2430 | * </td> |
||
| 2431 | * </tr> |
||
| 2432 | * <tr valign="top"> |
||
| 2433 | * <td><b>ENT_SUBSTITUTE</b></td> |
||
| 2434 | * <td> |
||
| 2435 | 5 | * Replace invalid code unit sequences with a Unicode Replacement Character |
|
| 2436 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
| 2437 | 5 | * </td> |
|
| 2438 | * </tr> |
||
| 2439 | * <tr valign="top"> |
||
| 2440 | * <td><b>ENT_DISALLOWED</b></td> |
||
| 2441 | * <td> |
||
| 2442 | * Replace invalid code points for the given document type with a |
||
| 2443 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
| 2444 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
| 2445 | * instance, to ensure the well-formedness of XML documents with |
||
| 2446 | * embedded external content. |
||
| 2447 | * </td> |
||
| 2448 | * </tr> |
||
| 2449 | * <tr valign="top"> |
||
| 2450 | * <td><b>ENT_HTML401</b></td> |
||
| 2451 | * <td> |
||
| 2452 | * Handle code as HTML 4.01. |
||
| 2453 | * </td> |
||
| 2454 | * </tr> |
||
| 2455 | * <tr valign="top"> |
||
| 2456 | * <td><b>ENT_XML1</b></td> |
||
| 2457 | * <td> |
||
| 2458 | * Handle code as XML 1. |
||
| 2459 | * </td> |
||
| 2460 | * </tr> |
||
| 2461 | * <tr valign="top"> |
||
| 2462 | * <td><b>ENT_XHTML</b></td> |
||
| 2463 | * <td> |
||
| 2464 | * Handle code as XHTML. |
||
| 2465 | * </td> |
||
| 2466 | * </tr> |
||
| 2467 | * <tr valign="top"> |
||
| 2468 | * <td><b>ENT_HTML5</b></td> |
||
| 2469 | * <td> |
||
| 2470 | * Handle code as HTML 5. |
||
| 2471 | * </td> |
||
| 2472 | * </tr> |
||
| 2473 | * </table> |
||
| 2474 | * </p> |
||
| 2475 | * @param string $encoding [optional] <p> |
||
| 2476 | * Like <b>htmlspecialchars</b>, |
||
| 2477 | * <b>htmlentities</b> takes an optional third argument |
||
| 2478 | * <i>encoding</i> which defines encoding used in |
||
| 2479 | * conversion. |
||
| 2480 | * Although this argument is technically optional, you are highly |
||
| 2481 | * encouraged to specify the correct value for your code. |
||
| 2482 | * </p> |
||
| 2483 | * @param bool $double_encode [optional] <p> |
||
| 2484 | * When <i>double_encode</i> is turned off PHP will not |
||
| 2485 | * encode existing html entities. The default is to convert everything. |
||
| 2486 | * </p> |
||
| 2487 | * |
||
| 2488 | 1 | * |
|
| 2489 | * @return string the encoded string. |
||
| 2490 | 1 | * </p> |
|
| 2491 | * <p> |
||
| 2492 | 1 | * If the input <i>string</i> contains an invalid code unit |
|
| 2493 | * sequence within the given <i>encoding</i> an empty string |
||
| 2494 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
| 2495 | * <b>ENT_SUBSTITUTE</b> flags are set. |
||
| 2496 | */ |
||
| 2497 | public static function htmlentities($str, $flags = ENT_COMPAT, $encoding = 'UTF-8', $double_encode = true) |
||
| 2501 | |||
| 2502 | /** |
||
| 2503 | * Convert special characters to HTML entities: UTF-8 version of htmlspecialchars() |
||
| 2504 | * |
||
| 2505 | * @link http://php.net/manual/en/function.htmlspecialchars.php |
||
| 2506 | * |
||
| 2507 | * @param string $str <p> |
||
| 2508 | * The string being converted. |
||
| 2509 | * </p> |
||
| 2510 | * @param int $flags [optional] <p> |
||
| 2511 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
||
| 2512 | * invalid code unit sequences and the used document type. The default is |
||
| 2513 | * ENT_COMPAT | ENT_HTML401. |
||
| 2514 | * <table> |
||
| 2515 | * Available <i>flags</i> constants |
||
| 2516 | * <tr valign="top"> |
||
| 2517 | * <td>Constant Name</td> |
||
| 2518 | * <td>Description</td> |
||
| 2519 | * </tr> |
||
| 2520 | * <tr valign="top"> |
||
| 2521 | * <td><b>ENT_COMPAT</b></td> |
||
| 2522 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 2523 | 1 | * </tr> |
|
| 2524 | * <tr valign="top"> |
||
| 2525 | 1 | * <td><b>ENT_QUOTES</b></td> |
|
| 2526 | * <td>Will convert both double and single quotes.</td> |
||
| 2527 | 1 | * </tr> |
|
| 2528 | * <tr valign="top"> |
||
| 2529 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 2530 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 2531 | * </tr> |
||
| 2532 | * <tr valign="top"> |
||
| 2533 | * <td><b>ENT_IGNORE</b></td> |
||
| 2534 | * <td> |
||
| 2535 | * Silently discard invalid code unit sequences instead of returning |
||
| 2536 | * an empty string. Using this flag is discouraged as it |
||
| 2537 | * may have security implications. |
||
| 2538 | * </td> |
||
| 2539 | 1 | * </tr> |
|
| 2540 | * <tr valign="top"> |
||
| 2541 | 1 | * <td><b>ENT_SUBSTITUTE</b></td> |
|
| 2542 | 1 | * <td> |
|
| 2543 | 1 | * Replace invalid code unit sequences with a Unicode Replacement Character |
|
| 2544 | 1 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
|
| 2545 | * </td> |
||
| 2546 | * </tr> |
||
| 2547 | 1 | * <tr valign="top"> |
|
| 2548 | * <td><b>ENT_DISALLOWED</b></td> |
||
| 2549 | * <td> |
||
| 2550 | * Replace invalid code points for the given document type with a |
||
| 2551 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
| 2552 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
| 2553 | * instance, to ensure the well-formedness of XML documents with |
||
| 2554 | * embedded external content. |
||
| 2555 | * </td> |
||
| 2556 | * </tr> |
||
| 2557 | * <tr valign="top"> |
||
| 2558 | * <td><b>ENT_HTML401</b></td> |
||
| 2559 | 6 | * <td> |
|
| 2560 | * Handle code as HTML 4.01. |
||
| 2561 | 6 | * </td> |
|
| 2562 | 6 | * </tr> |
|
| 2563 | 1 | * <tr valign="top"> |
|
| 2564 | * <td><b>ENT_XML1</b></td> |
||
| 2565 | * <td> |
||
| 2566 | 1 | * Handle code as XML 1. |
|
| 2567 | 1 | * </td> |
|
| 2568 | 6 | * </tr> |
|
| 2569 | 1 | * <tr valign="top"> |
|
| 2570 | 1 | * <td><b>ENT_XHTML</b></td> |
|
| 2571 | 1 | * <td> |
|
| 2572 | 1 | * Handle code as XHTML. |
|
| 2573 | 6 | * </td> |
|
| 2574 | 6 | * </tr> |
|
| 2575 | * <tr valign="top"> |
||
| 2576 | * <td><b>ENT_HTML5</b></td> |
||
| 2577 | * <td> |
||
| 2578 | 6 | * Handle code as HTML 5. |
|
| 2579 | 6 | * </td> |
|
| 2580 | 1 | * </tr> |
|
| 2581 | 1 | * </table> |
|
| 2582 | 6 | * </p> |
|
| 2583 | * @param string $encoding [optional] <p> |
||
| 2584 | 6 | * Defines encoding used in conversion. |
|
| 2585 | 4 | * </p> |
|
| 2586 | 4 | * <p> |
|
| 2587 | 4 | * For the purposes of this function, the encodings |
|
| 2588 | * ISO-8859-1, ISO-8859-15, |
||
| 2589 | * UTF-8, cp866, |
||
| 2590 | * cp1251, cp1252, and |
||
| 2591 | 6 | * KOI8-R are effectively equivalent, provided the |
|
| 2592 | * <i>string</i> itself is valid for the encoding, as |
||
| 2593 | * the characters affected by <b>htmlspecialchars</b> occupy |
||
| 2594 | * the same positions in all of these encodings. |
||
| 2595 | * </p> |
||
| 2596 | 6 | * @param bool $double_encode [optional] <p> |
|
| 2597 | 6 | * When <i>double_encode</i> is turned off PHP will not |
|
| 2598 | 6 | * encode existing html entities, the default is to convert everything. |
|
| 2599 | * </p> |
||
| 2600 | 6 | * |
|
| 2601 | * @return string The converted string. |
||
| 2602 | * </p> |
||
| 2603 | * <p> |
||
| 2604 | * If the input <i>string</i> contains an invalid code unit |
||
| 2605 | * sequence within the given <i>encoding</i> an empty string |
||
| 2606 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
| 2607 | * <b>ENT_SUBSTITUTE</b> flags are set. |
||
| 2608 | */ |
||
| 2609 | public static function htmlspecialchars($str, $flags = ENT_COMPAT, $encoding = 'UTF-8', $double_encode = true) |
||
| 2613 | |||
| 2614 | 11 | /** |
|
| 2615 | * checks whether iconv is available on the server |
||
| 2616 | 11 | * |
|
| 2617 | * @return bool True if available, False otherwise |
||
| 2618 | 11 | */ |
|
| 2619 | 11 | public static function iconv_loaded() |
|
| 2623 | 1 | ||
| 2624 | /** |
||
| 2625 | * Converts Integer to hexadecimal U+xxxx code point representation. |
||
| 2626 | * |
||
| 2627 | * @param int $int The integer to be converted to hexadecimal code point. |
||
| 2628 | * @param string $pfix |
||
| 2629 | * |
||
| 2630 | * @return string The code point, or empty string on failure. |
||
| 2631 | */ |
||
| 2632 | public static function int_to_hex($int, $pfix = 'U+') |
||
| 2644 | 11 | ||
| 2645 | 11 | /** |
|
| 2646 | 11 | * checks whether intl is available on the server |
|
| 2647 | 11 | * |
|
| 2648 | 11 | * @return bool True if available, False otherwise |
|
| 2649 | 11 | */ |
|
| 2650 | 11 | public static function intl_loaded() |
|
| 2654 | |||
| 2655 | 11 | /** |
|
| 2656 | * alias for "UTF8::is_ascii()" |
||
| 2657 | * |
||
| 2658 | * @param string $str |
||
| 2659 | * |
||
| 2660 | * @return boolean |
||
| 2661 | */ |
||
| 2662 | public static function isAscii($str) |
||
| 2666 | |||
| 2667 | 2 | /** |
|
| 2668 | * alias for "UTF8::is_base64" |
||
| 2669 | * |
||
| 2670 | * @param string $str |
||
| 2671 | * |
||
| 2672 | * @return bool |
||
| 2673 | */ |
||
| 2674 | public static function isBase64($str) |
||
| 2678 | |||
| 2679 | 2 | /** |
|
| 2680 | * alias for "UTF8::is_bom" |
||
| 2681 | 1 | * |
|
| 2682 | * @param string $utf8_chr |
||
| 2683 | 1 | * |
|
| 2684 | 1 | * @return boolean |
|
| 2685 | */ |
||
| 2686 | 1 | public static function isBom($utf8_chr) |
|
| 2690 | |||
| 2691 | /** |
||
| 2692 | * Try to check if a string is a json-string... |
||
| 2693 | * |
||
| 2694 | * @param $str |
||
| 2695 | * |
||
| 2696 | * @return bool |
||
| 2697 | * |
||
| 2698 | * @deprecated |
||
| 2699 | */ |
||
| 2700 | public static function isJson($str) |
||
| 2718 | 1 | ||
| 2719 | 1 | /** |
|
| 2720 | 1 | * alias for "UTF8::is_utf8" |
|
| 2721 | * |
||
| 2722 | 6 | * @param string $str |
|
| 2723 | * |
||
| 2724 | * @return bool |
||
| 2725 | */ |
||
| 2726 | public static function isUtf8($str) |
||
| 2730 | |||
| 2731 | /** |
||
| 2732 | * Checks if a string is 7 bit ASCII. |
||
| 2733 | * |
||
| 2734 | * @param string $str The string to check. |
||
| 2735 | * |
||
| 2736 | * @return bool <strong>true</strong> if it is ASCII<br /> |
||
| 2737 | * <strong>false</strong> otherwise |
||
| 2738 | */ |
||
| 2739 | public static function is_ascii($str) |
||
| 2743 | |||
| 2744 | /** |
||
| 2745 | * Returns true if the string is base64 encoded, false otherwise. |
||
| 2746 | * |
||
| 2747 | * @param string $str |
||
| 2748 | * |
||
| 2749 | * @return bool Whether or not $str is base64 encoded |
||
| 2750 | */ |
||
| 2751 | public static function is_base64($str) |
||
| 2765 | 1 | ||
| 2766 | 1 | /** |
|
| 2767 | 1 | * Check if the input is binary... (is look like a hack) |
|
| 2768 | * |
||
| 2769 | 5 | * @param string $input |
|
| 2770 | * |
||
| 2771 | * @return bool |
||
| 2772 | */ |
||
| 2773 | public static function is_binary($input) |
||
| 2790 | |||
| 2791 | /** |
||
| 2792 | * Check if the file is binary. |
||
| 2793 | * |
||
| 2794 | * @param string $file |
||
| 2795 | * |
||
| 2796 | * @return boolean |
||
| 2797 | */ |
||
| 2798 | public static function is_binary_file($file) |
||
| 2810 | |||
| 2811 | 1 | /** |
|
| 2812 | * Checks if the given string is exactly "UTF8 - Byte Order Mark". |
||
| 2813 | 1 | * |
|
| 2814 | 1 | * WARNING: Use "UTF8::string_has_bom()" if you will check BOM in a string. |
|
| 2815 | 1 | * |
|
| 2816 | * @param string $utf8_chr The input string. |
||
| 2817 | * |
||
| 2818 | * @return bool True if the $utf8_chr is Byte Order Mark, False otherwise. |
||
| 2819 | 1 | */ |
|
| 2820 | public static function is_bom($utf8_chr) |
||
| 2824 | |||
| 2825 | /** |
||
| 2826 | * Check if the string is UTF-16. |
||
| 2827 | * |
||
| 2828 | * @param string $str |
||
| 2829 | * |
||
| 2830 | * @return int|false false if is't not UTF16, 1 for UTF-16LE, 2 for UTF-16BE. |
||
| 2831 | */ |
||
| 2832 | View Code Duplication | public static function is_utf16($str) |
|
| 2879 | |||
| 2880 | /** |
||
| 2881 | * Check if the string is UTF-32. |
||
| 2882 | * |
||
| 2883 | * @param string $str |
||
| 2884 | * |
||
| 2885 | * @return int|false false if is't not UTF16, 1 for UTF-32LE, 2 for UTF-32BE. |
||
| 2886 | */ |
||
| 2887 | View Code Duplication | public static function is_utf32($str) |
|
| 2934 | |||
| 2935 | /** |
||
| 2936 | * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters. |
||
| 2937 | * |
||
| 2938 | * @see http://hsivonen.iki.fi/php-utf8/ |
||
| 2939 | * |
||
| 2940 | * @param string $str The string to be checked. |
||
| 2941 | * |
||
| 2942 | * @return bool |
||
| 2943 | */ |
||
| 2944 | 8 | public static function is_utf8($str) |
|
| 3068 | 1 | ||
| 3069 | /** |
||
| 3070 | 1 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
|
| 3071 | * Decodes a JSON string |
||
| 3072 | * |
||
| 3073 | * @link http://php.net/manual/en/function.json-decode.php |
||
| 3074 | * |
||
| 3075 | * @param string $json <p> |
||
| 3076 | * The <i>json</i> string being decoded. |
||
| 3077 | * </p> |
||
| 3078 | * <p> |
||
| 3079 | * This function only works with UTF-8 encoded strings. |
||
| 3080 | * </p> |
||
| 3081 | * <p>PHP implements a superset of |
||
| 3082 | 2 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
|
| 3083 | * only supports these values when they are nested inside an array or an object. |
||
| 3084 | 2 | * </p> |
|
| 3085 | * @param bool $assoc [optional] <p> |
||
| 3086 | * When <b>TRUE</b>, returned objects will be converted into |
||
| 3087 | * associative arrays. |
||
| 3088 | * </p> |
||
| 3089 | * @param int $depth [optional] <p> |
||
| 3090 | * User specified recursion depth. |
||
| 3091 | * </p> |
||
| 3092 | 2 | * @param int $options [optional] <p> |
|
| 3093 | * Bitmask of JSON decode options. Currently only |
||
| 3094 | 2 | * <b>JSON_BIGINT_AS_STRING</b> |
|
| 3095 | * is supported (default is to cast large integers as floats) |
||
| 3096 | * </p> |
||
| 3097 | * |
||
| 3098 | * @return mixed the value encoded in <i>json</i> in appropriate |
||
| 3099 | * PHP type. Values true, false and |
||
| 3100 | * null (case-insensitive) are returned as <b>TRUE</b>, <b>FALSE</b> |
||
| 3101 | * and <b>NULL</b> respectively. <b>NULL</b> is returned if the |
||
| 3102 | * <i>json</i> cannot be decoded or if the encoded |
||
| 3103 | * data is deeper than the recursion limit. |
||
| 3104 | */ |
||
| 3105 | public static function json_decode($json, $assoc = false, $depth = 512, $options = 0) |
||
| 3117 | |||
| 3118 | 1 | /** |
|
| 3119 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
||
| 3120 | * Returns the JSON representation of a value |
||
| 3121 | * |
||
| 3122 | * @link http://php.net/manual/en/function.json-encode.php |
||
| 3123 | * |
||
| 3124 | * @param mixed $value <p> |
||
| 3125 | * The <i>value</i> being encoded. Can be any type except |
||
| 3126 | * a resource. |
||
| 3127 | * </p> |
||
| 3128 | * <p> |
||
| 3129 | * All string data must be UTF-8 encoded. |
||
| 3130 | * </p> |
||
| 3131 | * <p>PHP implements a superset of |
||
| 3132 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
||
| 3133 | * only supports these values when they are nested inside an array or an object. |
||
| 3134 | * </p> |
||
| 3135 | * @param int $options [optional] <p> |
||
| 3136 | * Bitmask consisting of <b>JSON_HEX_QUOT</b>, |
||
| 3137 | * <b>JSON_HEX_TAG</b>, |
||
| 3138 | * <b>JSON_HEX_AMP</b>, |
||
| 3139 | * <b>JSON_HEX_APOS</b>, |
||
| 3140 | * <b>JSON_NUMERIC_CHECK</b>, |
||
| 3141 | * <b>JSON_PRETTY_PRINT</b>, |
||
| 3142 | * <b>JSON_UNESCAPED_SLASHES</b>, |
||
| 3143 | * <b>JSON_FORCE_OBJECT</b>, |
||
| 3144 | * <b>JSON_UNESCAPED_UNICODE</b>. The behaviour of these |
||
| 3145 | * constants is described on |
||
| 3146 | * the JSON constants page. |
||
| 3147 | * </p> |
||
| 3148 | * @param int $depth [optional] <p> |
||
| 3149 | * Set the maximum depth. Must be greater than zero. |
||
| 3150 | * </p> |
||
| 3151 | * |
||
| 3152 | * @return string a JSON encoded string on success or <b>FALSE</b> on failure. |
||
| 3153 | */ |
||
| 3154 | public static function json_encode($value, $options = 0, $depth = 512) |
||
| 3166 | |||
| 3167 | 4 | /** |
|
| 3168 | * Makes string's first char lowercase. |
||
| 3169 | * |
||
| 3170 | * @param string $str The input string |
||
| 3171 | 4 | * |
|
| 3172 | 4 | * @return string The resulting string |
|
| 3173 | 4 | */ |
|
| 3174 | public static function lcfirst($str) |
||
| 3178 | 4 | ||
| 3179 | /** |
||
| 3180 | 4 | * Strip whitespace or other characters from beginning of a UTF-8 string. |
|
| 3181 | * |
||
| 3182 | * WARNING: This is much slower then "ltrim()" !!!! |
||
| 3183 | * |
||
| 3184 | 4 | * @param string $str The string to be trimmed |
|
| 3185 | * @param string $chars Optional characters to be stripped |
||
| 3186 | 4 | * |
|
| 3187 | * @return string The string with unwanted characters stripped from the left |
||
| 3188 | */ |
||
| 3189 | View Code Duplication | public static function ltrim($str = '', $chars = INF) |
|
| 3201 | 4 | ||
| 3202 | 4 | /** |
|
| 3203 | 4 | * Returns the UTF-8 character with the maximum code point in the given data. |
|
| 3204 | * |
||
| 3205 | 4 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
|
| 3206 | 3 | * |
|
| 3207 | 3 | * @return string The character with the highest code point than others. |
|
| 3208 | 3 | */ |
|
| 3209 | 3 | View Code Duplication | public static function max($arg) |
| 3217 | |||
| 3218 | 4 | /** |
|
| 3219 | * Calculates and returns the maximum number of bytes taken by any |
||
| 3220 | * UTF-8 encoded character in the given string. |
||
| 3221 | * |
||
| 3222 | * @param string $str The original Unicode string. |
||
| 3223 | * |
||
| 3224 | * @return int An array of byte lengths of each character. |
||
| 3225 | */ |
||
| 3226 | public static function max_chr_width($str) |
||
| 3235 | |||
| 3236 | /** |
||
| 3237 | * checks whether mbstring is available on the server |
||
| 3238 | * |
||
| 3239 | * @return bool True if available, False otherwise |
||
| 3240 | */ |
||
| 3241 | public static function mbstring_loaded() |
||
| 3251 | |||
| 3252 | /** |
||
| 3253 | 10 | * Returns the UTF-8 character with the minimum code point in the given data. |
|
| 3254 | 10 | * |
|
| 3255 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
||
| 3256 | * |
||
| 3257 | * @return string The character with the lowest code point than others. |
||
| 3258 | 10 | */ |
|
| 3259 | View Code Duplication | public static function min($arg) |
|
| 3267 | 1 | ||
| 3268 | 1 | /** |
|
| 3269 | * Normalize the encoding-name input. |
||
| 3270 | 10 | * |
|
| 3271 | * @param string $encodingLabel e.g.: ISO, UTF8, WINDOWS-1251 etc. |
||
| 3272 | * |
||
| 3273 | 10 | * @return string e.g.: ISO-8859-1, UTF-8, ISO-8859-5 etc. |
|
| 3274 | 1 | */ |
|
| 3275 | 1 | public static function normalizeEncoding($encodingLabel) |
|
| 3303 | |||
| 3304 | /** |
||
| 3305 | * Normalize MS Word special characters. |
||
| 3306 | 8 | * |
|
| 3307 | * @param string $str The string to be normalized. |
||
| 3308 | 8 | * |
|
| 3309 | * @return string |
||
| 3310 | 8 | */ |
|
| 3311 | public static function normalize_msword($str) |
||
| 3323 | |||
| 3324 | /** |
||
| 3325 | * Normalize the whitespace. |
||
| 3326 | * |
||
| 3327 | * @param string $str The string to be normalized. |
||
| 3328 | * @param bool $keepNonBreakingSpace Set to true, to keep non-breaking-spaces. |
||
| 3329 | * |
||
| 3330 | * @return string |
||
| 3331 | */ |
||
| 3332 | public static function normalize_whitespace($str, $keepNonBreakingSpace = false) |
||
| 3350 | |||
| 3351 | /** |
||
| 3352 | * Format a number with grouped thousands. |
||
| 3353 | * |
||
| 3354 | * @param float $number |
||
| 3355 | * @param int $decimals |
||
| 3356 | * @param string $dec_point |
||
| 3357 | 1 | * @param string $thousands_sep |
|
| 3358 | * |
||
| 3359 | 1 | * @return string |
|
| 3360 | */ |
||
| 3361 | public static function number_format($number, $decimals = 0, $dec_point = '.', $thousands_sep = ',') |
||
| 3381 | 3 | ||
| 3382 | /** |
||
| 3383 | 3 | * Calculates Unicode code point of the given UTF-8 encoded character. |
|
| 3384 | * |
||
| 3385 | 3 | * @param string $s The character of which to calculate code point. |
|
| 3386 | 3 | * |
|
| 3387 | 3 | * @return int Unicode code point of the given character,<br /> |
|
| 3388 | * 0 on invalid UTF-8 byte sequence. |
||
| 3389 | 3 | */ |
|
| 3390 | public static function ord($s) |
||
| 3413 | 1 | ||
| 3414 | /** |
||
| 3415 | * Parses the string into variables. |
||
| 3416 | * |
||
| 3417 | 1 | * WARNING: This differs from parse_str() by returning the results |
|
| 3418 | * instead of placing them in the local scope! |
||
| 3419 | * |
||
| 3420 | * @link http://php.net/manual/en/function.parse-str.php |
||
| 3421 | * |
||
| 3422 | * @param string $str <p> |
||
| 3423 | * The input string. |
||
| 3424 | * </p> |
||
| 3425 | * @param array $result <p> |
||
| 3426 | * If the second parameter arr is present, |
||
| 3427 | * variables are stored in this variable as array elements instead. |
||
| 3428 | * </p> |
||
| 3429 | * |
||
| 3430 | * @return void |
||
| 3431 | */ |
||
| 3432 | public static function parse_str($str, &$result) |
||
| 3441 | |||
| 3442 | /** |
||
| 3443 | * checks if \u modifier is available that enables Unicode support in PCRE. |
||
| 3444 | * |
||
| 3445 | * @return bool True if support is available, false otherwise |
||
| 3446 | */ |
||
| 3447 | public static function pcre_utf8_support() |
||
| 3452 | |||
| 3453 | /** |
||
| 3454 | * Create an array containing a range of UTF-8 characters. |
||
| 3455 | * |
||
| 3456 | * @param mixed $var1 Numeric or hexadecimal code points, or a UTF-8 character to start from. |
||
| 3457 | * @param mixed $var2 Numeric or hexadecimal code points, or a UTF-8 character to end at. |
||
| 3458 | * |
||
| 3459 | * @return array |
||
| 3460 | */ |
||
| 3461 | 1 | public static function range($var1, $var2) |
|
| 3499 | |||
| 3500 | 1 | /** |
|
| 3501 | * Remove the BOM from UTF-8 / UTF-16 / UTF-32 strings. |
||
| 3502 | * |
||
| 3503 | * @param string $str |
||
| 3504 | * |
||
| 3505 | * @return string |
||
| 3506 | */ |
||
| 3507 | public static function removeBOM($str = '') |
||
| 3547 | |||
| 3548 | /** |
||
| 3549 | * Removes duplicate occurrences of a string in another string. |
||
| 3550 | * |
||
| 3551 | * @param string $str The base string |
||
| 3552 | * @param string|array $what String to search for in the base string |
||
| 3553 | * |
||
| 3554 | 22 | * @return string The result string with removed duplicates |
|
| 3555 | */ |
||
| 3556 | 22 | public static function remove_duplicates($str, $what = ' ') |
|
| 3570 | |||
| 3571 | /** |
||
| 3572 | * Remove Invisible Characters |
||
| 3573 | * |
||
| 3574 | * This prevents sandwiching null characters |
||
| 3575 | * between ascii characters, like Java\0script. |
||
| 3576 | * |
||
| 3577 | 24 | * copy&past from https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Common.php |
|
| 3578 | * |
||
| 3579 | 24 | * @param string $str |
|
| 3580 | * @param bool $url_encoded |
||
| 3581 | 24 | * |
|
| 3582 | 2 | * @return string |
|
| 3583 | */ |
||
| 3584 | public static function remove_invisible_characters($str, $url_encoded = true) |
||
| 3604 | |||
| 3605 | 6 | /** |
|
| 3606 | 1 | * replace diamond question mark (�) |
|
| 3607 | * |
||
| 3608 | * @param string $str |
||
| 3609 | 1 | * @param string $unknown |
|
| 3610 | * |
||
| 3611 | * @return string |
||
| 3612 | 1 | */ |
|
| 3613 | public static function replace_diamond_question_mark($str, $unknown = '?') |
||
| 3627 | 1 | ||
| 3628 | 1 | /** |
|
| 3629 | * Strip whitespace or other characters from end of a UTF-8 string. |
||
| 3630 | * |
||
| 3631 | * WARNING: This is much slower then "rtrim()" !!!! |
||
| 3632 | * |
||
| 3633 | * @param string $str The string to be trimmed |
||
| 3634 | * @param string $chars Optional characters to be stripped |
||
| 3635 | * |
||
| 3636 | * @return string The string with unwanted characters stripped from the right |
||
| 3637 | */ |
||
| 3638 | 1 | View Code Duplication | public static function rtrim($str = '', $chars = INF) |
| 3650 | 1 | ||
| 3651 | /** |
||
| 3652 | * rxClass |
||
| 3653 | 6 | * |
|
| 3654 | 6 | * @param string $s |
|
| 3655 | * @param string $class |
||
| 3656 | 6 | * |
|
| 3657 | 4 | * @return string |
|
| 3658 | */ |
||
| 3659 | 4 | protected static function rxClass($s, $class = '') |
|
| 3695 | |||
| 3696 | /** |
||
| 3697 | * Echo native UTF8-Support libs, e.g. for debugging. |
||
| 3698 | */ |
||
| 3699 | public static function showSupport() |
||
| 3705 | |||
| 3706 | /** |
||
| 3707 | * Converts a UTF-8 character to HTML Numbered Entity like "{". |
||
| 3708 | * |
||
| 3709 | * @param string $chr The Unicode character to be encoded as numbered entity. |
||
| 3710 | * |
||
| 3711 | * @return string The HTML numbered entity. |
||
| 3712 | */ |
||
| 3713 | 1 | public static function single_chr_html_encode($chr) |
|
| 3721 | |||
| 3722 | /** |
||
| 3723 | * Convert a string to an array of Unicode characters. |
||
| 3724 | * |
||
| 3725 | 1 | * @param string $str The string to split into array. |
|
| 3726 | * @param int $length Max character length of each array element. |
||
| 3727 | 1 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string. |
|
| 3728 | * |
||
| 3729 | * @return array An array containing chunks of the string. |
||
| 3730 | */ |
||
| 3731 | public static function split($str, $length = 1, $cleanUtf8 = false) |
||
| 3800 | 1 | ||
| 3801 | 1 | /** |
|
| 3802 | 1 | * Optimized "mb_detect_encoding()"-function -> with support for UTF-16 and UTF-32. |
|
| 3803 | 1 | * |
|
| 3804 | 1 | * @param string $str |
|
| 3805 | * |
||
| 3806 | 1 | * @return false|string The detected string-encoding e.g. UTF-8 or UTF-16BE,<br /> |
|
| 3807 | * otherwise it will return false. |
||
| 3808 | 1 | */ |
|
| 3809 | 1 | public static function str_detect_encoding($str) |
|
| 3880 | 1 | ||
| 3881 | /** |
||
| 3882 | 1 | * str_ireplace |
|
| 3883 | * |
||
| 3884 | 1 | * @param string $search |
|
| 3885 | 1 | * @param string $replace |
|
| 3886 | 1 | * @param string $subject |
|
| 3887 | * @param null $count |
||
| 3888 | 1 | * |
|
| 3889 | 1 | * @return string |
|
| 3890 | 1 | */ |
|
| 3891 | 1 | public static function str_ireplace($search, $replace, $subject, &$count = null) |
|
| 3909 | 2 | ||
| 3910 | 2 | /** |
|
| 3911 | 2 | * Limit the number of characters in a string, but also after the next word. |
|
| 3912 | * |
||
| 3913 | 2 | * @param string $str |
|
| 3914 | 2 | * @param int $length |
|
| 3915 | * @param string $strAddOn |
||
| 3916 | * |
||
| 3917 | * @return string |
||
| 3918 | */ |
||
| 3919 | public static function str_limit_after_word($str, $length = 100, $strAddOn = '...') |
||
| 3948 | |||
| 3949 | /** |
||
| 3950 | * Pad a UTF-8 string to given length with another string. |
||
| 3951 | * |
||
| 3952 | * @param string $input The input string |
||
| 3953 | * @param int $pad_length The length of return string |
||
| 3954 | 2 | * @param string $pad_string String to use for padding the input string |
|
| 3955 | * @param int $pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT or STR_PAD_BOTH |
||
| 3956 | 2 | * |
|
| 3957 | * @return string Returns the padded string |
||
| 3958 | 2 | */ |
|
| 3959 | 2 | public static function str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) |
|
| 3994 | |||
| 3995 | /** |
||
| 3996 | * Repeat a string. |
||
| 3997 | * |
||
| 3998 | * @param string $input <p> |
||
| 3999 | * The string to be repeated. |
||
| 4000 | * </p> |
||
| 4001 | * @param int $multiplier <p> |
||
| 4002 | * Number of time the input string should be |
||
| 4003 | * repeated. |
||
| 4004 | * </p> |
||
| 4005 | * <p> |
||
| 4006 | * multiplier has to be greater than or equal to 0. |
||
| 4007 | * If the multiplier is set to 0, the function |
||
| 4008 | 1 | * will return an empty string. |
|
| 4009 | * </p> |
||
| 4010 | 1 | * |
|
| 4011 | * @return string the repeated string. |
||
| 4012 | 1 | */ |
|
| 4013 | public static function str_repeat($input, $multiplier) |
||
| 4019 | |||
| 4020 | /** |
||
| 4021 | * INFO: this is only a wrapper for "str_replace()" -> the original functions is already UTF-8 safe |
||
| 4022 | * |
||
| 4023 | 1 | * (PHP 4, PHP 5)<br/> |
|
| 4024 | * Replace all occurrences of the search string with the replacement string |
||
| 4025 | 1 | * |
|
| 4026 | 1 | * @link http://php.net/manual/en/function.str-replace.php |
|
| 4027 | 1 | * |
|
| 4028 | * @param mixed $search <p> |
||
| 4029 | 1 | * The value being searched for, otherwise known as the needle. |
|
| 4030 | 1 | * An array may be used to designate multiple needles. |
|
| 4031 | 1 | * </p> |
|
| 4032 | 1 | * @param mixed $replace <p> |
|
| 4033 | 1 | * The replacement value that replaces found search |
|
| 4034 | * values. An array may be used to designate multiple replacements. |
||
| 4035 | 1 | * </p> |
|
| 4036 | * @param mixed $subject <p> |
||
| 4037 | * The string or array being searched and replaced on, |
||
| 4038 | * otherwise known as the haystack. |
||
| 4039 | * </p> |
||
| 4040 | * <p> |
||
| 4041 | * If subject is an array, then the search and |
||
| 4042 | * replace is performed with every entry of |
||
| 4043 | * subject, and the return value is an array as |
||
| 4044 | * well. |
||
| 4045 | * </p> |
||
| 4046 | * @param int $count [optional] If passed, this will hold the number of matched and replaced needles. |
||
| 4047 | * |
||
| 4048 | * @return mixed This function returns a string or an array with the replaced values. |
||
| 4049 | */ |
||
| 4050 | public static function str_replace($search, $replace, $subject, &$count = null) |
||
| 4054 | |||
| 4055 | /** |
||
| 4056 | * Shuffles all the characters in the string. |
||
| 4057 | * |
||
| 4058 | * @param string $str The input string |
||
| 4059 | * |
||
| 4060 | * @return string The shuffled string. |
||
| 4061 | 8 | */ |
|
| 4062 | public static function str_shuffle($str) |
||
| 4070 | |||
| 4071 | 7 | /** |
|
| 4072 | * Sort all characters according to code points. |
||
| 4073 | 7 | * |
|
| 4074 | 1 | * @param string $str A UTF-8 string. |
|
| 4075 | 1 | * @param bool $unique Sort unique. If true, repeated characters are ignored. |
|
| 4076 | 1 | * @param bool $desc If true, will sort characters in reverse code point order. |
|
| 4077 | * |
||
| 4078 | * @return string String of sorted characters |
||
| 4079 | 7 | */ |
|
| 4080 | 1 | public static function str_sort($str, $unique = false, $desc = false) |
|
| 4096 | |||
| 4097 | /** |
||
| 4098 | * Convert a string to an array. |
||
| 4099 | * |
||
| 4100 | * @param string $str |
||
| 4101 | * @param int $len |
||
| 4102 | * |
||
| 4103 | * @return array |
||
| 4104 | */ |
||
| 4105 | 1 | public static function str_split($str, $len = 1) |
|
| 4146 | |||
| 4147 | /** |
||
| 4148 | * Get a binary representation of a specific character. |
||
| 4149 | * |
||
| 4150 | 14 | * @param string $str The input character. |
|
| 4151 | * |
||
| 4152 | 14 | * @return string |
|
| 4153 | */ |
||
| 4154 | 14 | public static function str_to_binary($str) |
|
| 4173 | |||
| 4174 | /** |
||
| 4175 | * US-ASCII transliterations of Unicode text. |
||
| 4176 | * |
||
| 4177 | * Ported Sean M. Burke's Text::Unidecode Perl module (He did all the hard work!) |
||
| 4178 | * Warning: you should only pass this well formed UTF-8! |
||
| 4179 | * Be aware it works by making a copy of the input string which it appends transliterated |
||
| 4180 | * characters to - it uses a PHP output buffer to do this - it means, memory use will increase, |
||
| 4181 | * requiring up to the same amount again as the input string |
||
| 4182 | * |
||
| 4183 | * @see http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm |
||
| 4184 | * |
||
| 4185 | * @author <[email protected]> |
||
| 4186 | * |
||
| 4187 | * @param string $str UTF-8 string to convert |
||
| 4188 | * @param string $unknown Character use if character unknown. (default is ?) |
||
| 4189 | * |
||
| 4190 | * @return string US-ASCII string |
||
| 4191 | */ |
||
| 4192 | public static function str_transliterate($str, $unknown = '?') |
||
| 4284 | |||
| 4285 | /** |
||
| 4286 | * Counts number of words in the UTF-8 string. |
||
| 4287 | * |
||
| 4288 | * @param string $s The input string. |
||
| 4289 | * @param int $format |
||
| 4290 | * @param string $charlist |
||
| 4291 | * |
||
| 4292 | * @return array|float|string The number of words in the string |
||
| 4293 | */ |
||
| 4294 | public static function str_word_count($s, $format = 0, $charlist = '') |
||
| 4319 | |||
| 4320 | /** |
||
| 4321 | * Case-insensitive string comparison. |
||
| 4322 | * |
||
| 4323 | * @param string $str1 |
||
| 4324 | * @param string $str2 |
||
| 4325 | * |
||
| 4326 | * @return int Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. |
||
| 4327 | */ |
||
| 4328 | public static function strcasecmp($str1, $str2) |
||
| 4332 | |||
| 4333 | /** |
||
| 4334 | * String comparison. |
||
| 4335 | * |
||
| 4336 | * @param string $str1 |
||
| 4337 | * @param string $str2 |
||
| 4338 | * |
||
| 4339 | * @return int <strong>< 0</strong> if str1 is less than str2<br /> |
||
| 4340 | * <strong>> 0</strong> if str1 is greater than str2<br /> |
||
| 4341 | * <strong>0</strong> if they are equal. |
||
| 4342 | */ |
||
| 4343 | public static function strcmp($str1, $str2) |
||
| 4350 | |||
| 4351 | /** |
||
| 4352 | * Find length of initial segment not matching mask. |
||
| 4353 | * |
||
| 4354 | * @param string $str |
||
| 4355 | * @param string $charlist |
||
| 4356 | * @param int $start |
||
| 4357 | * @param int $len |
||
| 4358 | * |
||
| 4359 | * @return int|null |
||
| 4360 | */ |
||
| 4361 | public static function strcspn($str, $charlist, $start = 0, $len = 2147483647) |
||
| 4380 | |||
| 4381 | /** |
||
| 4382 | * Makes a UTF-8 string from code points. |
||
| 4383 | * |
||
| 4384 | * @param array $array Integer or Hexadecimal codepoints |
||
| 4385 | * |
||
| 4386 | * @return string UTF-8 encoded string |
||
| 4387 | */ |
||
| 4388 | public static function string($array) |
||
| 4400 | |||
| 4401 | /** |
||
| 4402 | * Checks if string starts with "UTF-8 BOM" character. |
||
| 4403 | * |
||
| 4404 | * @param string $str The input string. |
||
| 4405 | * |
||
| 4406 | * @return bool True if the string has BOM at the start, False otherwise. |
||
| 4407 | */ |
||
| 4408 | public static function string_has_bom($str) |
||
| 4412 | |||
| 4413 | /** |
||
| 4414 | * Strip HTML and PHP tags from a string. |
||
| 4415 | * |
||
| 4416 | * @link http://php.net/manual/en/function.strip-tags.php |
||
| 4417 | * |
||
| 4418 | * @param string $str <p> |
||
| 4419 | * The input string. |
||
| 4420 | * </p> |
||
| 4421 | * @param string $allowable_tags [optional] <p> |
||
| 4422 | * You can use the optional second parameter to specify tags which should |
||
| 4423 | * not be stripped. |
||
| 4424 | * </p> |
||
| 4425 | * <p> |
||
| 4426 | * HTML comments and PHP tags are also stripped. This is hardcoded and |
||
| 4427 | * can not be changed with allowable_tags. |
||
| 4428 | * </p> |
||
| 4429 | * |
||
| 4430 | * @return string the stripped string. |
||
| 4431 | */ |
||
| 4432 | public static function strip_tags($str, $allowable_tags = null) |
||
| 4439 | |||
| 4440 | /** |
||
| 4441 | * Finds position of first occurrence of a string within another, case insensitive. |
||
| 4442 | * |
||
| 4443 | * @link http://php.net/manual/en/function.mb-stripos.php |
||
| 4444 | * |
||
| 4445 | * @param string $haystack <p> |
||
| 4446 | * The string from which to get the position of the first occurrence |
||
| 4447 | * of needle |
||
| 4448 | * </p> |
||
| 4449 | * @param string $needle <p> |
||
| 4450 | * The string to find in haystack |
||
| 4451 | * </p> |
||
| 4452 | * @param int $offset [optional] <p> |
||
| 4453 | * The position in haystack |
||
| 4454 | * to start searching |
||
| 4455 | * </p> |
||
| 4456 | * @param string $encoding |
||
| 4457 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 4458 | * |
||
| 4459 | * @return int Return the numeric position of the first occurrence of |
||
| 4460 | * needle in the haystack |
||
| 4461 | * string, or false if needle is not found. |
||
| 4462 | */ |
||
| 4463 | public static function stripos($haystack, $needle, $offset = null, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 4487 | |||
| 4488 | /** |
||
| 4489 | * Returns all of haystack starting from and including the first occurrence of needle to the end. |
||
| 4490 | * |
||
| 4491 | * @param string $str |
||
| 4492 | * @param string $needle |
||
| 4493 | * @param bool $before_needle |
||
| 4494 | * |
||
| 4495 | * @return false|string |
||
| 4496 | */ |
||
| 4497 | public static function stristr($str, $needle, $before_needle = false) |
||
| 4508 | |||
| 4509 | /** |
||
| 4510 | * Get the string length, not the byte-length! |
||
| 4511 | * |
||
| 4512 | * @link http://php.net/manual/en/function.mb-strlen.php |
||
| 4513 | * |
||
| 4514 | * @param string $str The string being checked for length. |
||
| 4515 | * @param string $encoding Set the charset for e.g. "mb_" function |
||
| 4516 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 4517 | * |
||
| 4518 | * @return int the number of characters in |
||
| 4519 | * string str having character encoding |
||
| 4520 | * encoding. A multi-byte character is |
||
| 4521 | * counted as 1. |
||
| 4522 | */ |
||
| 4523 | public static function strlen($str, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 4545 | |||
| 4546 | /** |
||
| 4547 | * Case insensitive string comparisons using a "natural order" algorithm. |
||
| 4548 | * |
||
| 4549 | * @param string $str1 |
||
| 4550 | * @param string $str2 |
||
| 4551 | * |
||
| 4552 | * @return int Similar to other string comparison functions, this one returns < 0 if str1 is less than str2 > 0 if |
||
| 4553 | * str1 is greater than str2, and 0 if they are equal. |
||
| 4554 | */ |
||
| 4555 | public static function strnatcasecmp($str1, $str2) |
||
| 4559 | |||
| 4560 | /** |
||
| 4561 | * String comparisons using a "natural order" algorithm. |
||
| 4562 | * |
||
| 4563 | * @param string $str1 |
||
| 4564 | * @param string $str2 |
||
| 4565 | * |
||
| 4566 | * @return int Similar to other string comparison functions, this one returns < 0 if str1 is less than str2; > 0 if |
||
| 4567 | * str1 is greater than str2, and 0 if they are equal. |
||
| 4568 | */ |
||
| 4569 | public static function strnatcmp($str1, $str2) |
||
| 4573 | |||
| 4574 | /** |
||
| 4575 | * Case-insensitive string comparison of the first n characters. |
||
| 4576 | * |
||
| 4577 | * @param string $str1 |
||
| 4578 | * @param string $str2 |
||
| 4579 | * @param int $len |
||
| 4580 | * |
||
| 4581 | * @return int Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. |
||
| 4582 | */ |
||
| 4583 | public static function strncasecmp($str1, $str2, $len) |
||
| 4587 | |||
| 4588 | /** |
||
| 4589 | * Comparison of the first n characters. |
||
| 4590 | * |
||
| 4591 | * @param string $str1 |
||
| 4592 | * @param string $str2 |
||
| 4593 | * @param int $len |
||
| 4594 | * |
||
| 4595 | * @return int <strong>< 0</strong> if str1 is less than str2<br /> |
||
| 4596 | * <strong>> 0</strong> if str1 is greater than str2<br /> |
||
| 4597 | * <strong>0</strong> if they are equal |
||
| 4598 | */ |
||
| 4599 | public static function strncmp($str1, $str2, $len) |
||
| 4603 | |||
| 4604 | /** |
||
| 4605 | * Search a string for any of a set of characters. |
||
| 4606 | * |
||
| 4607 | * @param string $s |
||
| 4608 | * @param string $charList |
||
| 4609 | * |
||
| 4610 | * @return string|false |
||
| 4611 | */ |
||
| 4612 | public static function strpbrk($s, $charList) |
||
| 4620 | |||
| 4621 | /** |
||
| 4622 | * Find position of first occurrence of string in a string. |
||
| 4623 | * |
||
| 4624 | * @link http://php.net/manual/en/function.mb-strpos.php |
||
| 4625 | * |
||
| 4626 | * @param string $haystack <p> |
||
| 4627 | * The string being checked. |
||
| 4628 | * </p> |
||
| 4629 | * @param string $needle <p> |
||
| 4630 | * The position counted from the beginning of haystack. |
||
| 4631 | * </p> |
||
| 4632 | * @param int $offset [optional] <p> |
||
| 4633 | * The search offset. If it is not specified, 0 is used. |
||
| 4634 | * </p> |
||
| 4635 | * @param string $encoding |
||
| 4636 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string. |
||
| 4637 | * |
||
| 4638 | * @return int The numeric position of the first occurrence of needle in the haystack string.<br /> |
||
| 4639 | * If needle is not found it returns false. |
||
| 4640 | */ |
||
| 4641 | public static function strpos($haystack, $needle, $offset = 0, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 4695 | |||
| 4696 | /** |
||
| 4697 | * Finds the last occurrence of a character in a string within another. |
||
| 4698 | * |
||
| 4699 | * @link http://php.net/manual/en/function.mb-strrchr.php |
||
| 4700 | * |
||
| 4701 | * @param string $haystack <p> |
||
| 4702 | * The string from which to get the last occurrence |
||
| 4703 | * of needle |
||
| 4704 | * </p> |
||
| 4705 | * @param string $needle <p> |
||
| 4706 | * The string to find in haystack |
||
| 4707 | * </p> |
||
| 4708 | * @param bool $part [optional] <p> |
||
| 4709 | * Determines which portion of haystack |
||
| 4710 | * this function returns. |
||
| 4711 | * If set to true, it returns all of haystack |
||
| 4712 | * from the beginning to the last occurrence of needle. |
||
| 4713 | * If set to false, it returns all of haystack |
||
| 4714 | * from the last occurrence of needle to the end, |
||
| 4715 | * </p> |
||
| 4716 | * @param string $encoding [optional] <p> |
||
| 4717 | * Character encoding name to use. |
||
| 4718 | * If it is omitted, internal character encoding is used. |
||
| 4719 | * </p> |
||
| 4720 | * |
||
| 4721 | * @return string the portion of haystack. |
||
| 4722 | * or false if needle is not found. |
||
| 4723 | */ |
||
| 4724 | public static function strrchr($haystack, $needle, $part = false, $encoding = 'UTF-8') |
||
| 4730 | |||
| 4731 | /** |
||
| 4732 | * Reverses characters order in the string. |
||
| 4733 | * |
||
| 4734 | * @param string $str The input string |
||
| 4735 | * |
||
| 4736 | * @return string The string with characters in the reverse sequence |
||
| 4737 | */ |
||
| 4738 | public static function strrev($str) |
||
| 4742 | |||
| 4743 | /** |
||
| 4744 | * Finds the last occurrence of a character in a string within another, case insensitive. |
||
| 4745 | * |
||
| 4746 | * @link http://php.net/manual/en/function.mb-strrichr.php |
||
| 4747 | * |
||
| 4748 | * @param string $haystack <p> |
||
| 4749 | * The string from which to get the last occurrence |
||
| 4750 | * of needle |
||
| 4751 | * </p> |
||
| 4752 | * @param string $needle <p> |
||
| 4753 | * The string to find in haystack |
||
| 4754 | * </p> |
||
| 4755 | * @param bool $part [optional] <p> |
||
| 4756 | * Determines which portion of haystack |
||
| 4757 | * this function returns. |
||
| 4758 | * If set to true, it returns all of haystack |
||
| 4759 | * from the beginning to the last occurrence of needle. |
||
| 4760 | * If set to false, it returns all of haystack |
||
| 4761 | * from the last occurrence of needle to the end, |
||
| 4762 | * </p> |
||
| 4763 | * @param string $encoding [optional] <p> |
||
| 4764 | * Character encoding name to use. |
||
| 4765 | * If it is omitted, internal character encoding is used. |
||
| 4766 | * </p> |
||
| 4767 | * |
||
| 4768 | * @return string the portion of haystack. |
||
| 4769 | * or false if needle is not found. |
||
| 4770 | */ |
||
| 4771 | public static function strrichr($haystack, $needle, $part = false, $encoding = 'UTF-8') |
||
| 4777 | |||
| 4778 | /** |
||
| 4779 | * Find position of last occurrence of a case-insensitive string. |
||
| 4780 | * |
||
| 4781 | * @param string $haystack The string to look in |
||
| 4782 | * @param string $needle The string to look for |
||
| 4783 | * @param int $offset (Optional) Number of characters to ignore in the beginning or end |
||
| 4784 | * |
||
| 4785 | * @return int The position of offset |
||
| 4786 | */ |
||
| 4787 | public static function strripos($haystack, $needle, $offset = 0) |
||
| 4791 | |||
| 4792 | /** |
||
| 4793 | * Find position of last occurrence of a string in a string. |
||
| 4794 | * |
||
| 4795 | * @link http://php.net/manual/en/function.mb-strrpos.php |
||
| 4796 | * |
||
| 4797 | * @param string $haystack <p> |
||
| 4798 | * The string being checked, for the last occurrence |
||
| 4799 | * of needle |
||
| 4800 | * </p> |
||
| 4801 | * @param string $needle <p> |
||
| 4802 | * The string to find in haystack. |
||
| 4803 | * </p> |
||
| 4804 | * @param int $offset [optional] May be specified to begin searching an arbitrary number of characters into |
||
| 4805 | * the string. Negative values will stop searching at an arbitrary point |
||
| 4806 | * prior to the end of the string. |
||
| 4807 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 4808 | * |
||
| 4809 | * @return int the numeric position of |
||
| 4810 | * the last occurrence of needle in the |
||
| 4811 | * haystack string. If |
||
| 4812 | * needle is not found, it returns false. |
||
| 4813 | */ |
||
| 4814 | public static function strrpos($haystack, $needle, $offset = null, $cleanUtf8 = false) |
||
| 4865 | |||
| 4866 | /** |
||
| 4867 | * Finds the length of the initial segment of a string consisting entirely of characters contained within a given |
||
| 4868 | * mask. |
||
| 4869 | * |
||
| 4870 | * @param string $s |
||
| 4871 | * @param string $mask |
||
| 4872 | * @param int $start |
||
| 4873 | * @param int $len |
||
| 4874 | * |
||
| 4875 | * @return int|null |
||
| 4876 | */ |
||
| 4877 | public static function strspn($s, $mask, $start = 0, $len = 2147483647) |
||
| 4885 | |||
| 4886 | /** |
||
| 4887 | * Returns part of haystack string from the first occurrence of needle to the end of haystack. |
||
| 4888 | * |
||
| 4889 | * @link http://php.net/manual/en/function.grapheme-strstr.php |
||
| 4890 | * |
||
| 4891 | * @param string $haystack <p> |
||
| 4892 | * The input string. Must be valid UTF-8. |
||
| 4893 | * </p> |
||
| 4894 | * @param string $needle <p> |
||
| 4895 | * The string to look for. Must be valid UTF-8. |
||
| 4896 | * </p> |
||
| 4897 | * @param bool $before_needle [optional] <p> |
||
| 4898 | * If <b>TRUE</b>, grapheme_strstr() returns the part of the |
||
| 4899 | * haystack before the first occurrence of the needle (excluding the needle). |
||
| 4900 | * </p> |
||
| 4901 | * |
||
| 4902 | * @return string the portion of string, or FALSE if needle is not found. |
||
| 4903 | */ |
||
| 4904 | public static function strstr($haystack, $needle, $before_needle = false) |
||
| 4910 | |||
| 4911 | /** |
||
| 4912 | * Unicode transformation for case-less matching. |
||
| 4913 | * |
||
| 4914 | * @link http://unicode.org/reports/tr21/tr21-5.html |
||
| 4915 | * |
||
| 4916 | * @param string $str |
||
| 4917 | * @param bool $full |
||
| 4918 | * |
||
| 4919 | * @return string |
||
| 4920 | */ |
||
| 4921 | public static function strtocasefold($str, $full = true) |
||
| 4948 | |||
| 4949 | /** |
||
| 4950 | * (PHP 4 >= 4.3.0, PHP 5)<br/> |
||
| 4951 | * Make a string lowercase. |
||
| 4952 | * |
||
| 4953 | * @link http://php.net/manual/en/function.mb-strtolower.php |
||
| 4954 | * |
||
| 4955 | * @param string $str <p> |
||
| 4956 | * The string being lowercased. |
||
| 4957 | * </p> |
||
| 4958 | * @param string $encoding |
||
| 4959 | * |
||
| 4960 | * @return string str with all alphabetic characters converted to lowercase. |
||
| 4961 | */ |
||
| 4962 | public static function strtolower($str, $encoding = 'UTF-8') |
||
| 4975 | |||
| 4976 | /** |
||
| 4977 | * Generic case sensitive transformation for collation matching. |
||
| 4978 | * |
||
| 4979 | * @param string $s |
||
| 4980 | * |
||
| 4981 | * @return string |
||
| 4982 | */ |
||
| 4983 | protected static function strtonatfold($s) |
||
| 4987 | |||
| 4988 | /** |
||
| 4989 | * Make a string uppercase. |
||
| 4990 | * |
||
| 4991 | * @link http://php.net/manual/en/function.mb-strtoupper.php |
||
| 4992 | * |
||
| 4993 | * @param string $str <p> |
||
| 4994 | * The string being uppercased. |
||
| 4995 | * </p> |
||
| 4996 | * @param string $encoding |
||
| 4997 | * |
||
| 4998 | * @return string str with all alphabetic characters converted to uppercase. |
||
| 4999 | */ |
||
| 5000 | public static function strtoupper($str, $encoding = 'UTF-8') |
||
| 5031 | |||
| 5032 | /** |
||
| 5033 | * Translate characters or replace sub-strings. |
||
| 5034 | * |
||
| 5035 | * @param string $s |
||
| 5036 | * @param string $from |
||
| 5037 | * @param string $to |
||
| 5038 | * |
||
| 5039 | * @return string |
||
| 5040 | */ |
||
| 5041 | public static function strtr($s, $from, $to = INF) |
||
| 5060 | |||
| 5061 | /** |
||
| 5062 | * Return the width of a string. |
||
| 5063 | * |
||
| 5064 | * @param string $s |
||
| 5065 | * |
||
| 5066 | * @return int |
||
| 5067 | */ |
||
| 5068 | public static function strwidth($s) |
||
| 5075 | |||
| 5076 | /** |
||
| 5077 | * Get part of a string. |
||
| 5078 | * |
||
| 5079 | * @link http://php.net/manual/en/function.mb-substr.php |
||
| 5080 | * |
||
| 5081 | * @param string $str <p> |
||
| 5082 | * The string being checked. |
||
| 5083 | * </p> |
||
| 5084 | * @param int $start <p> |
||
| 5085 | * The first position used in str. |
||
| 5086 | * </p> |
||
| 5087 | * @param int $length [optional] <p> |
||
| 5088 | * The maximum length of the returned string. |
||
| 5089 | * </p> |
||
| 5090 | * @param string $encoding |
||
| 5091 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 5092 | * |
||
| 5093 | * @return string mb_substr returns the portion of |
||
| 5094 | * str specified by the start and length parameters. |
||
| 5095 | */ |
||
| 5096 | public static function substr($str, $start = 0, $length = null, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 5142 | |||
| 5143 | /** |
||
| 5144 | * Binary safe comparison of two strings from an offset, up to length characters. |
||
| 5145 | * |
||
| 5146 | * @param string $main_str The main string being compared. |
||
| 5147 | * @param string $str The secondary string being compared. |
||
| 5148 | * @param int $offset The start position for the comparison. If negative, it starts counting from the |
||
| 5149 | * end of the string. |
||
| 5150 | * @param int $length The length of the comparison. The default value is the largest of the length of |
||
| 5151 | * the str compared to the length of main_str less the offset. |
||
| 5152 | * @param boolean $case_insensitivity If case_insensitivity is TRUE, comparison is case insensitive. |
||
| 5153 | * |
||
| 5154 | * @return int |
||
| 5155 | */ |
||
| 5156 | public static function substr_compare($main_str, $str, $offset, $length = 2147483647, $case_insensitivity = false) |
||
| 5163 | |||
| 5164 | /** |
||
| 5165 | * Count the number of sub-string occurrences. |
||
| 5166 | * |
||
| 5167 | * @param string $haystack The string to search in. |
||
| 5168 | * @param string $needle The string to search for. |
||
| 5169 | * @param int $offset The offset where to start counting. |
||
| 5170 | * @param int $length The maximum length after the specified offset to search for the substring. |
||
| 5171 | * |
||
| 5172 | * @return int number of occurrences of $needle |
||
| 5173 | */ |
||
| 5174 | public static function substr_count($haystack, $needle, $offset = 0, $length = null) |
||
| 5190 | |||
| 5191 | /** |
||
| 5192 | * Replace text within a portion of a string. |
||
| 5193 | * |
||
| 5194 | * source: https://gist.github.com/stemar/8287074 |
||
| 5195 | * |
||
| 5196 | * @param string|array $str |
||
| 5197 | * @param string|array $replacement |
||
| 5198 | 1 | * @param int $start |
|
| 5199 | * @param null|int $length |
||
| 5200 | 1 | * |
|
| 5201 | * @return array|string |
||
| 5202 | */ |
||
| 5203 | public static function substr_replace($str, $replacement, $start, $length = null) |
||
| 5269 | |||
| 5270 | 6 | /** |
|
| 5271 | 1 | * Returns a case swapped version of the string. |
|
| 5272 | 1 | * |
|
| 5273 | 6 | * @param string $str |
|
| 5274 | * @param string $encoding |
||
| 5275 | * |
||
| 5276 | 6 | * @return string each character's case swapped |
|
| 5277 | */ |
||
| 5278 | 6 | public static function swapCase($str, $encoding = 'UTF-8') |
|
| 5304 | 1 | ||
| 5305 | /** |
||
| 5306 | 1 | * alias for "UTF8::to_ascii()" |
|
| 5307 | 1 | * |
|
| 5308 | * @param string $s The input string e.g. a UTF-8 String |
||
| 5309 | * @param string $subst_chr |
||
| 5310 | * |
||
| 5311 | * @return string |
||
| 5312 | */ |
||
| 5313 | public static function toAscii($s, $subst_chr = '?') |
||
| 5317 | |||
| 5318 | /** |
||
| 5319 | * alias for "UTF8::to_latin1()" |
||
| 5320 | 1 | * |
|
| 5321 | * @param $str |
||
| 5322 | 1 | * |
|
| 5323 | * @return string |
||
| 5324 | */ |
||
| 5325 | public static function toLatin1($str) |
||
| 5329 | |||
| 5330 | /** |
||
| 5331 | * alias for "UTF8::to_utf8" |
||
| 5332 | * |
||
| 5333 | * @param string $str |
||
| 5334 | * |
||
| 5335 | * @return string |
||
| 5336 | */ |
||
| 5337 | public static function toUTF8($str) |
||
| 5341 | |||
| 5342 | /** |
||
| 5343 | * convert to ASCII |
||
| 5344 | * |
||
| 5345 | * @param string $s The input string e.g. a UTF-8 String |
||
| 5346 | * @param string $subst_chr |
||
| 5347 | * |
||
| 5348 | * @return string |
||
| 5349 | */ |
||
| 5350 | public static function to_ascii($s, $subst_chr = '?') |
||
| 5421 | |||
| 5422 | /** |
||
| 5423 | * alias for "UTF8::to_win1252()" |
||
| 5424 | * |
||
| 5425 | * @param string $str |
||
| 5426 | * |
||
| 5427 | * @return array|string |
||
| 5428 | */ |
||
| 5429 | public static function to_iso8859($str) |
||
| 5433 | |||
| 5434 | /** |
||
| 5435 | * alias for "UTF8::to_win1252()" |
||
| 5436 | * |
||
| 5437 | 10 | * @param string|array $str |
|
| 5438 | * |
||
| 5439 | 10 | * @return string|array |
|
| 5440 | 10 | */ |
|
| 5441 | public static function to_latin1($str) |
||
| 5445 | |||
| 5446 | /** |
||
| 5447 | 9 | * This function leaves UTF8 characters alone, while converting almost all non-UTF8 to UTF8. |
|
| 5448 | * |
||
| 5449 | 9 | * - It assumes that the encoding of the original string is either Windows-1252 or ISO 8859-1. |
|
| 5450 | * |
||
| 5451 | * - It may fail to convert characters to UTF-8 if they fall into one of these scenarios: |
||
| 5452 | * |
||
| 5453 | 9 | * 1) when any of these characters: ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß |
|
| 5454 | 9 | * are followed by any of these: ("group B") |
|
| 5455 | * ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶•¸¹º»¼½¾¿ |
||
| 5456 | 9 | * For example: %ABREPRESENT%C9%BB. «REPRESENTÉ» |
|
| 5457 | * The "«" (%AB) character will be converted, but the "É" followed by "»" (%C9%BB) |
||
| 5458 | * is also a valid unicode character, and will be left unchanged. |
||
| 5459 | 1 | * |
|
| 5460 | 1 | * 2) when any of these: àáâãäåæçèéêëìíîï are followed by TWO chars from group B, |
|
| 5461 | 1 | * 3) when any of these: ðñòó are followed by THREE chars from group B. |
|
| 5462 | * |
||
| 5463 | 9 | * @param string $str Any string or array. |
|
| 5464 | 9 | * |
|
| 5465 | * @return string The same string, but UTF8 encoded. |
||
| 5466 | */ |
||
| 5467 | public static function to_utf8($str) |
||
| 5573 | |||
| 5574 | /** |
||
| 5575 | * Convert a string into win1252. |
||
| 5576 | * |
||
| 5577 | * @param string|array $str |
||
| 5578 | * |
||
| 5579 | * @return string|array |
||
| 5580 | */ |
||
| 5581 | 1 | protected static function to_win1252($str) |
|
| 5597 | 1 | ||
| 5598 | 1 | /** |
|
| 5599 | 1 | * Strip whitespace or other characters from beginning or end of a UTF-8 string. |
|
| 5600 | 1 | * |
|
| 5601 | 1 | * INFO: This is slower then "trim()" |
|
| 5602 | * |
||
| 5603 | * But we can only use the original-function, if we use <= 7-Bit in the string / chars |
||
| 5604 | * but the check for ACSII (7-Bit) cost more time, then we can safe here. |
||
| 5605 | * |
||
| 5606 | * @param string $str The string to be trimmed |
||
| 5607 | * @param string $chars Optional characters to be stripped |
||
| 5608 | * |
||
| 5609 | * @return string The trimmed string |
||
| 5610 | */ |
||
| 5611 | public static function trim($str = '', $chars = INF) |
||
| 5626 | |||
| 5627 | /** |
||
| 5628 | * Makes string's first char uppercase. |
||
| 5629 | * |
||
| 5630 | * @param string $str The input string |
||
| 5631 | * |
||
| 5632 | * @return string The resulting string |
||
| 5633 | */ |
||
| 5634 | public static function ucfirst($str) |
||
| 5638 | |||
| 5639 | /** |
||
| 5640 | * alias for "UTF8::ucfirst" |
||
| 5641 | * |
||
| 5642 | * @param $str |
||
| 5643 | * |
||
| 5644 | * @return string |
||
| 5645 | */ |
||
| 5646 | public static function ucword($str) |
||
| 5650 | |||
| 5651 | /** |
||
| 5652 | * Uppercase for all words in the string. |
||
| 5653 | * |
||
| 5654 | * @param string $str |
||
| 5655 | * @param array $exceptions |
||
| 5656 | * |
||
| 5657 | * @return string |
||
| 5658 | */ |
||
| 5659 | public static function ucwords($str, $exceptions = array()) |
||
| 5692 | 2 | ||
| 5693 | /** |
||
| 5694 | 2 | * Multi decode html entity & fix urlencoded-win1252-chars. |
|
| 5695 | 2 | * |
|
| 5696 | 2 | * e.g: |
|
| 5697 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 5698 | 1 | * 'D%FCsseldorf' => 'Düsseldorf' |
|
| 5699 | 1 | * 'Düsseldorf' => 'Düsseldorf' |
|
| 5700 | 1 | * 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' |
|
| 5701 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 5702 | * 'D%C3%BCsseldorf' => 'Düsseldorf' |
||
| 5703 | * 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' |
||
| 5704 | * 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf' |
||
| 5705 | * |
||
| 5706 | 2 | * @param string $str |
|
| 5707 | * |
||
| 5708 | 2 | * @return string |
|
| 5709 | 2 | */ |
|
| 5710 | public static function urldecode($str) |
||
| 5733 | |||
| 5734 | /** |
||
| 5735 | * Return a array with "urlencoded"-win1252 -> UTF-8 |
||
| 5736 | * |
||
| 5737 | * @return mixed |
||
| 5738 | */ |
||
| 5739 | protected static function urldecode_fix_win1252_chars() |
||
| 5970 | |||
| 5971 | /** |
||
| 5972 | * Decodes an UTF-8 string to ISO-8859-1. |
||
| 5973 | * |
||
| 5974 | * @param string $str |
||
| 5975 | * |
||
| 5976 | * @return string |
||
| 5977 | */ |
||
| 5978 | public static function utf8_decode($str) |
||
| 6001 | |||
| 6002 | /** |
||
| 6003 | * Encodes an ISO-8859-1 string to UTF-8. |
||
| 6004 | * |
||
| 6005 | * @param string $str |
||
| 6006 | * |
||
| 6007 | * @return string |
||
| 6008 | */ |
||
| 6009 | public static function utf8_encode($str) |
||
| 6028 | |||
| 6029 | /** |
||
| 6030 | * fix -> utf8-win1252 chars |
||
| 6031 | * |
||
| 6032 | * If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1 |
||
| 6033 | * (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. |
||
| 6034 | * See: http://en.wikipedia.org/wiki/Windows-1252 |
||
| 6035 | * |
||
| 6036 | * @deprecated use "UTF8::fix_simple_utf8()" |
||
| 6037 | * |
||
| 6038 | * @param string $str |
||
| 6039 | * |
||
| 6040 | * @return string |
||
| 6041 | */ |
||
| 6042 | public static function utf8_fix_win1252_chars($str) |
||
| 6046 | |||
| 6047 | /** |
||
| 6048 | * Returns an array with all utf8 whitespace characters. |
||
| 6049 | * |
||
| 6050 | * @see : http://www.bogofilter.org/pipermail/bogofilter/2003-March/001889.html |
||
| 6051 | * |
||
| 6052 | * @author: Derek E. [email protected] |
||
| 6053 | * |
||
| 6054 | * @return array an array with all known whitespace characters as values and the type of whitespace as keys |
||
| 6055 | * as defined in above URL |
||
| 6056 | */ |
||
| 6057 | public static function whitespace_table() |
||
| 6061 | |||
| 6062 | /** |
||
| 6063 | * Limit the number of words in a string. |
||
| 6064 | * |
||
| 6065 | * @param string $str |
||
| 6066 | * @param int $words |
||
| 6067 | * @param string $strAddOn |
||
| 6068 | * |
||
| 6069 | * @return string |
||
| 6070 | */ |
||
| 6071 | public static function words_limit($str, $words = 100, $strAddOn = '...') |
||
| 6091 | |||
| 6092 | /** |
||
| 6093 | * Wraps a string to a given number of characters. |
||
| 6094 | * |
||
| 6095 | * @param string $str |
||
| 6096 | * @param int $width |
||
| 6097 | * @param string $break |
||
| 6098 | * @param bool $cut |
||
| 6099 | * |
||
| 6100 | * @return false|string Returns the given string wrapped at the specified length. |
||
| 6101 | */ |
||
| 6102 | public static function wordwrap($str, $width = 75, $break = "\n", $cut = false) |
||
| 6158 | |||
| 6159 | /** |
||
| 6160 | * Returns an array of Unicode White Space characters. |
||
| 6161 | * |
||
| 6162 | * @return array An array with numeric code point as key and White Space Character as value. |
||
| 6163 | */ |
||
| 6164 | public static function ws() |
||
| 6168 | |||
| 6169 | } |
||
| 6170 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: