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 |
||
| 13 | class UTF8 |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | protected static $win1252ToUtf8 = array( |
||
| 19 | 128 => "\xe2\x82\xac", // EURO SIGN |
||
| 20 | 130 => "\xe2\x80\x9a", // SINGLE LOW-9 QUOTATION MARK |
||
| 21 | 131 => "\xc6\x92", // LATIN SMALL LETTER F WITH HOOK |
||
| 22 | 132 => "\xe2\x80\x9e", // DOUBLE LOW-9 QUOTATION MARK |
||
| 23 | 133 => "\xe2\x80\xa6", // HORIZONTAL ELLIPSIS |
||
| 24 | 134 => "\xe2\x80\xa0", // DAGGER |
||
| 25 | 135 => "\xe2\x80\xa1", // DOUBLE DAGGER |
||
| 26 | 136 => "\xcb\x86", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 27 | 137 => "\xe2\x80\xb0", // PER MILLE SIGN |
||
| 28 | 138 => "\xc5\xa0", // LATIN CAPITAL LETTER S WITH CARON |
||
| 29 | 139 => "\xe2\x80\xb9", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 30 | 140 => "\xc5\x92", // LATIN CAPITAL LIGATURE OE |
||
| 31 | 142 => "\xc5\xbd", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 32 | 145 => "\xe2\x80\x98", // LEFT SINGLE QUOTATION MARK |
||
| 33 | 146 => "\xe2\x80\x99", // RIGHT SINGLE QUOTATION MARK |
||
| 34 | 147 => "\xe2\x80\x9c", // LEFT DOUBLE QUOTATION MARK |
||
| 35 | 148 => "\xe2\x80\x9d", // RIGHT DOUBLE QUOTATION MARK |
||
| 36 | 149 => "\xe2\x80\xa2", // BULLET |
||
| 37 | 150 => "\xe2\x80\x93", // EN DASH |
||
| 38 | 151 => "\xe2\x80\x94", // EM DASH |
||
| 39 | 152 => "\xcb\x9c", // SMALL TILDE |
||
| 40 | 153 => "\xe2\x84\xa2", // TRADE MARK SIGN |
||
| 41 | 154 => "\xc5\xa1", // LATIN SMALL LETTER S WITH CARON |
||
| 42 | 155 => "\xe2\x80\xba", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 43 | 156 => "\xc5\x93", // LATIN SMALL LIGATURE OE |
||
| 44 | 158 => "\xc5\xbe", // LATIN SMALL LETTER Z WITH CARON |
||
| 45 | 159 => "\xc5\xb8", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
||
| 46 | ); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var array |
||
| 50 | */ |
||
| 51 | protected static $cp1252ToUtf8 = array( |
||
| 52 | '' => '€', |
||
| 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 | * Numeric code point => UTF-8 Character |
||
| 83 | * |
||
| 84 | * url: http://www.w3schools.com/charsets/ref_utf_punctuation.asp |
||
| 85 | * |
||
| 86 | * @var array |
||
| 87 | */ |
||
| 88 | protected static $whitespace = array( |
||
| 89 | // NUL Byte |
||
| 90 | 0 => "\x0", |
||
| 91 | // Tab |
||
| 92 | 9 => "\x9", |
||
| 93 | // New Line |
||
| 94 | 10 => "\xa", |
||
| 95 | // Vertical Tab |
||
| 96 | 11 => "\xb", |
||
| 97 | // Carriage Return |
||
| 98 | 13 => "\xd", |
||
| 99 | // Ordinary Space |
||
| 100 | 32 => "\x20", |
||
| 101 | // NO-BREAK SPACE |
||
| 102 | 160 => "\xc2\xa0", |
||
| 103 | // OGHAM SPACE MARK |
||
| 104 | 5760 => "\xe1\x9a\x80", |
||
| 105 | // MONGOLIAN VOWEL SEPARATOR |
||
| 106 | 6158 => "\xe1\xa0\x8e", |
||
| 107 | // EN QUAD |
||
| 108 | 8192 => "\xe2\x80\x80", |
||
| 109 | // EM QUAD |
||
| 110 | 8193 => "\xe2\x80\x81", |
||
| 111 | // EN SPACE |
||
| 112 | 8194 => "\xe2\x80\x82", |
||
| 113 | // EM SPACE |
||
| 114 | 8195 => "\xe2\x80\x83", |
||
| 115 | // THREE-PER-EM SPACE |
||
| 116 | 8196 => "\xe2\x80\x84", |
||
| 117 | // FOUR-PER-EM SPACE |
||
| 118 | 8197 => "\xe2\x80\x85", |
||
| 119 | // SIX-PER-EM SPACE |
||
| 120 | 8198 => "\xe2\x80\x86", |
||
| 121 | // FIGURE SPACE |
||
| 122 | 8199 => "\xe2\x80\x87", |
||
| 123 | // PUNCTUATION SPACE |
||
| 124 | 8200 => "\xe2\x80\x88", |
||
| 125 | // THIN SPACE |
||
| 126 | 8201 => "\xe2\x80\x89", |
||
| 127 | //HAIR SPACE |
||
| 128 | 8202 => "\xe2\x80\x8a", |
||
| 129 | // LINE SEPARATOR |
||
| 130 | 8232 => "\xe2\x80\xa8", |
||
| 131 | // PARAGRAPH SEPARATOR |
||
| 132 | 8233 => "\xe2\x80\xa9", |
||
| 133 | // NARROW NO-BREAK SPACE |
||
| 134 | 8239 => "\xe2\x80\xaf", |
||
| 135 | // MEDIUM MATHEMATICAL SPACE |
||
| 136 | 8287 => "\xe2\x81\x9f", |
||
| 137 | // IDEOGRAPHIC SPACE |
||
| 138 | 12288 => "\xe3\x80\x80", |
||
| 139 | ); |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var array |
||
| 143 | */ |
||
| 144 | protected static $whitespaceTable = array( |
||
| 145 | 'SPACE' => "\x20", |
||
| 146 | 'NO-BREAK SPACE' => "\xc2\xa0", |
||
| 147 | 'OGHAM SPACE MARK' => "\xe1\x9a\x80", |
||
| 148 | 'EN QUAD' => "\xe2\x80\x80", |
||
| 149 | 'EM QUAD' => "\xe2\x80\x81", |
||
| 150 | 'EN SPACE' => "\xe2\x80\x82", |
||
| 151 | 'EM SPACE' => "\xe2\x80\x83", |
||
| 152 | 'THREE-PER-EM SPACE' => "\xe2\x80\x84", |
||
| 153 | 'FOUR-PER-EM SPACE' => "\xe2\x80\x85", |
||
| 154 | 'SIX-PER-EM SPACE' => "\xe2\x80\x86", |
||
| 155 | 'FIGURE SPACE' => "\xe2\x80\x87", |
||
| 156 | 'PUNCTUATION SPACE' => "\xe2\x80\x88", |
||
| 157 | 'THIN SPACE' => "\xe2\x80\x89", |
||
| 158 | 'HAIR SPACE' => "\xe2\x80\x8a", |
||
| 159 | 'LINE SEPARATOR' => "\xe2\x80\xa8", |
||
| 160 | 'PARAGRAPH SEPARATOR' => "\xe2\x80\xa9", |
||
| 161 | 'ZERO WIDTH SPACE' => "\xe2\x80\x8b", |
||
| 162 | 'NARROW NO-BREAK SPACE' => "\xe2\x80\xaf", |
||
| 163 | 'MEDIUM MATHEMATICAL SPACE' => "\xe2\x81\x9f", |
||
| 164 | 'IDEOGRAPHIC SPACE' => "\xe3\x80\x80", |
||
| 165 | ); |
||
| 166 | |||
| 167 | /** |
||
| 168 | * bidirectional text chars |
||
| 169 | * |
||
| 170 | * url: https://www.w3.org/International/questions/qa-bidi-unicode-controls |
||
| 171 | * |
||
| 172 | * @var array |
||
| 173 | */ |
||
| 174 | protected static $bidiUniCodeControlsTable = array( |
||
| 175 | // LEFT-TO-RIGHT EMBEDDING (use -> dir = "ltr") |
||
| 176 | 8234 => "\xE2\x80\xAA", |
||
| 177 | // RIGHT-TO-LEFT EMBEDDING (use -> dir = "rtl") |
||
| 178 | 8235 => "\xE2\x80\xAB", |
||
| 179 | // POP DIRECTIONAL FORMATTING // (use -> </bdo>) |
||
| 180 | 8236 => "\xE2\x80\xAC", |
||
| 181 | // LEFT-TO-RIGHT OVERRIDE // (use -> <bdo dir = "ltr">) |
||
| 182 | 8237 => "\xE2\x80\xAD", |
||
| 183 | // RIGHT-TO-LEFT OVERRIDE // (use -> <bdo dir = "rtl">) |
||
| 184 | 8238 => "\xE2\x80\xAE", |
||
| 185 | // LEFT-TO-RIGHT ISOLATE // (use -> dir = "ltr") |
||
| 186 | 8294 => "\xE2\x81\xA6", |
||
| 187 | // RIGHT-TO-LEFT ISOLATE // (use -> dir = "rtl") |
||
| 188 | 8295 => "\xE2\x81\xA7", |
||
| 189 | // FIRST STRONG ISOLATE // (use -> dir = "auto") |
||
| 190 | 8296 => "\xE2\x81\xA8", |
||
| 191 | // POP DIRECTIONAL ISOLATE |
||
| 192 | 8297 => "\xE2\x81\xA9", |
||
| 193 | ); |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @var array |
||
| 197 | */ |
||
| 198 | protected static $commonCaseFold = array( |
||
| 199 | 'ſ' => 's', |
||
| 200 | "\xCD\x85" => 'ι', |
||
| 201 | 'ς' => 'σ', |
||
| 202 | "\xCF\x90" => 'β', |
||
| 203 | "\xCF\x91" => 'θ', |
||
| 204 | "\xCF\x95" => 'φ', |
||
| 205 | "\xCF\x96" => 'π', |
||
| 206 | "\xCF\xB0" => 'κ', |
||
| 207 | "\xCF\xB1" => 'ρ', |
||
| 208 | "\xCF\xB5" => 'ε', |
||
| 209 | "\xE1\xBA\x9B" => "\xE1\xB9\xA1", |
||
| 210 | "\xE1\xBE\xBE" => 'ι', |
||
| 211 | ); |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var array |
||
| 215 | */ |
||
| 216 | protected static $brokenUtf8ToUtf8 = array( |
||
| 217 | "\xc2\x80" => "\xe2\x82\xac", // EURO SIGN |
||
| 218 | "\xc2\x82" => "\xe2\x80\x9a", // SINGLE LOW-9 QUOTATION MARK |
||
| 219 | "\xc2\x83" => "\xc6\x92", // LATIN SMALL LETTER F WITH HOOK |
||
| 220 | "\xc2\x84" => "\xe2\x80\x9e", // DOUBLE LOW-9 QUOTATION MARK |
||
| 221 | "\xc2\x85" => "\xe2\x80\xa6", // HORIZONTAL ELLIPSIS |
||
| 222 | "\xc2\x86" => "\xe2\x80\xa0", // DAGGER |
||
| 223 | "\xc2\x87" => "\xe2\x80\xa1", // DOUBLE DAGGER |
||
| 224 | "\xc2\x88" => "\xcb\x86", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 225 | "\xc2\x89" => "\xe2\x80\xb0", // PER MILLE SIGN |
||
| 226 | "\xc2\x8a" => "\xc5\xa0", // LATIN CAPITAL LETTER S WITH CARON |
||
| 227 | "\xc2\x8b" => "\xe2\x80\xb9", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 228 | "\xc2\x8c" => "\xc5\x92", // LATIN CAPITAL LIGATURE OE |
||
| 229 | "\xc2\x8e" => "\xc5\xbd", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 230 | "\xc2\x91" => "\xe2\x80\x98", // LEFT SINGLE QUOTATION MARK |
||
| 231 | "\xc2\x92" => "\xe2\x80\x99", // RIGHT SINGLE QUOTATION MARK |
||
| 232 | "\xc2\x93" => "\xe2\x80\x9c", // LEFT DOUBLE QUOTATION MARK |
||
| 233 | "\xc2\x94" => "\xe2\x80\x9d", // RIGHT DOUBLE QUOTATION MARK |
||
| 234 | "\xc2\x95" => "\xe2\x80\xa2", // BULLET |
||
| 235 | "\xc2\x96" => "\xe2\x80\x93", // EN DASH |
||
| 236 | "\xc2\x97" => "\xe2\x80\x94", // EM DASH |
||
| 237 | "\xc2\x98" => "\xcb\x9c", // SMALL TILDE |
||
| 238 | "\xc2\x99" => "\xe2\x84\xa2", // TRADE MARK SIGN |
||
| 239 | "\xc2\x9a" => "\xc5\xa1", // LATIN SMALL LETTER S WITH CARON |
||
| 240 | "\xc2\x9b" => "\xe2\x80\xba", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 241 | "\xc2\x9c" => "\xc5\x93", // LATIN SMALL LIGATURE OE |
||
| 242 | "\xc2\x9e" => "\xc5\xbe", // LATIN SMALL LETTER Z WITH CARON |
||
| 243 | "\xc2\x9f" => "\xc5\xb8", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
||
| 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 | 'È' => 'È', |
||
| 275 | 'É' => 'É', |
||
| 276 | 'Ê' => 'Ê', |
||
| 277 | 'Ë' => 'Ë', |
||
| 278 | 'ÃŒ' => 'Ì', |
||
| 279 | 'Ã' => 'Í', |
||
| 280 | 'ÃŽ' => 'Î', |
||
| 281 | 'Ã' => 'Ï', |
||
| 282 | 'Ñ' => 'Ñ', |
||
| 283 | 'Ã’' => 'Ò', |
||
| 284 | 'Ó' => 'Ó', |
||
| 285 | 'Ô' => 'Ô', |
||
| 286 | 'Õ' => 'Õ', |
||
| 287 | 'Ø' => 'Ø', |
||
| 288 | 'Ã¥' => 'å', |
||
| 289 | 'æ' => 'æ', |
||
| 290 | 'ç' => 'ç', |
||
| 291 | 'ì' => 'ì', |
||
| 292 | 'Ã' => 'í', |
||
| 293 | 'î' => 'î', |
||
| 294 | 'ï' => 'ï', |
||
| 295 | 'ð' => 'ð', |
||
| 296 | 'ñ' => 'ñ', |
||
| 297 | 'õ' => 'õ', |
||
| 298 | 'ø' => 'ø', |
||
| 299 | 'ý' => 'ý', |
||
| 300 | 'ÿ' => 'ÿ', |
||
| 301 | '€' => '€', |
||
| 302 | ); |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @var array |
||
| 306 | */ |
||
| 307 | protected static $utf8ToWin1252 = array( |
||
| 308 | "\xe2\x82\xac" => "\x80", // EURO SIGN |
||
| 309 | "\xe2\x80\x9a" => "\x82", // SINGLE LOW-9 QUOTATION MARK |
||
| 310 | "\xc6\x92" => "\x83", // LATIN SMALL LETTER F WITH HOOK |
||
| 311 | "\xe2\x80\x9e" => "\x84", // DOUBLE LOW-9 QUOTATION MARK |
||
| 312 | "\xe2\x80\xa6" => "\x85", // HORIZONTAL ELLIPSIS |
||
| 313 | "\xe2\x80\xa0" => "\x86", // DAGGER |
||
| 314 | "\xe2\x80\xa1" => "\x87", // DOUBLE DAGGER |
||
| 315 | "\xcb\x86" => "\x88", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 316 | "\xe2\x80\xb0" => "\x89", // PER MILLE SIGN |
||
| 317 | "\xc5\xa0" => "\x8a", // LATIN CAPITAL LETTER S WITH CARON |
||
| 318 | "\xe2\x80\xb9" => "\x8b", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 319 | "\xc5\x92" => "\x8c", // LATIN CAPITAL LIGATURE OE |
||
| 320 | "\xc5\xbd" => "\x8e", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 321 | "\xe2\x80\x98" => "\x91", // LEFT SINGLE QUOTATION MARK |
||
| 322 | "\xe2\x80\x99" => "\x92", // RIGHT SINGLE QUOTATION MARK |
||
| 323 | "\xe2\x80\x9c" => "\x93", // LEFT DOUBLE QUOTATION MARK |
||
| 324 | "\xe2\x80\x9d" => "\x94", // RIGHT DOUBLE QUOTATION MARK |
||
| 325 | "\xe2\x80\xa2" => "\x95", // BULLET |
||
| 326 | "\xe2\x80\x93" => "\x96", // EN DASH |
||
| 327 | "\xe2\x80\x94" => "\x97", // EM DASH |
||
| 328 | "\xcb\x9c" => "\x98", // SMALL TILDE |
||
| 329 | "\xe2\x84\xa2" => "\x99", // TRADE MARK SIGN |
||
| 330 | "\xc5\xa1" => "\x9a", // LATIN SMALL LETTER S WITH CARON |
||
| 331 | "\xe2\x80\xba" => "\x9b", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 332 | "\xc5\x93" => "\x9c", // LATIN SMALL LIGATURE OE |
||
| 333 | "\xc5\xbe" => "\x9e", // LATIN SMALL LETTER Z WITH CARON |
||
| 334 | "\xc5\xb8" => "\x9f", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
||
| 335 | ); |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @var array |
||
| 339 | */ |
||
| 340 | protected static $utf8MSWord = array( |
||
| 341 | "\xc2\xab" => '"', // « (U+00AB) in UTF-8 |
||
| 342 | "\xc2\xbb" => '"', // » (U+00BB) in UTF-8 |
||
| 343 | "\xe2\x80\x98" => "'", // ‘ (U+2018) in UTF-8 |
||
| 344 | "\xe2\x80\x99" => "'", // ’ (U+2019) in UTF-8 |
||
| 345 | "\xe2\x80\x9a" => "'", // ‚ (U+201A) in UTF-8 |
||
| 346 | "\xe2\x80\x9b" => "'", // ‛ (U+201B) in UTF-8 |
||
| 347 | "\xe2\x80\x9c" => '"', // “ (U+201C) in UTF-8 |
||
| 348 | "\xe2\x80\x9d" => '"', // ” (U+201D) in UTF-8 |
||
| 349 | "\xe2\x80\x9e" => '"', // „ (U+201E) in UTF-8 |
||
| 350 | "\xe2\x80\x9f" => '"', // ‟ (U+201F) in UTF-8 |
||
| 351 | "\xe2\x80\xb9" => "'", // ‹ (U+2039) in UTF-8 |
||
| 352 | "\xe2\x80\xba" => "'", // › (U+203A) in UTF-8 |
||
| 353 | "\xe2\x80\x93" => '-', // – (U+2013) in UTF-8 |
||
| 354 | "\xe2\x80\x94" => '-', // — (U+2014) in UTF-8 |
||
| 355 | "\xe2\x80\xa6" => '...' // … (U+2026) in UTF-8 |
||
| 356 | ); |
||
| 357 | |||
| 358 | protected static $iconvEncoding = array( |
||
| 359 | 'ANSI_X3.4-1968', |
||
| 360 | 'ANSI_X3.4-1986', |
||
| 361 | 'ASCII', |
||
| 362 | 'CP367', |
||
| 363 | 'IBM367', |
||
| 364 | 'ISO-IR-6', |
||
| 365 | 'ISO646-US', |
||
| 366 | 'ISO_646.IRV:1991', |
||
| 367 | 'US', |
||
| 368 | 'US-ASCII', |
||
| 369 | 'CSASCII', |
||
| 370 | 'UTF-8', |
||
| 371 | 'ISO-10646-UCS-2', |
||
| 372 | 'UCS-2', |
||
| 373 | 'CSUNICODE', |
||
| 374 | 'UCS-2BE', |
||
| 375 | 'UNICODE-1-1', |
||
| 376 | 'UNICODEBIG', |
||
| 377 | 'CSUNICODE11', |
||
| 378 | 'UCS-2LE', |
||
| 379 | 'UNICODELITTLE', |
||
| 380 | 'ISO-10646-UCS-4', |
||
| 381 | 'UCS-4', |
||
| 382 | 'CSUCS4', |
||
| 383 | 'UCS-4BE', |
||
| 384 | 'UCS-4LE', |
||
| 385 | 'UTF-16', |
||
| 386 | 'UTF-16BE', |
||
| 387 | 'UTF-16LE', |
||
| 388 | 'UTF-32', |
||
| 389 | 'UTF-32BE', |
||
| 390 | 'UTF-32LE', |
||
| 391 | 'UNICODE-1-1-UTF-7', |
||
| 392 | 'UTF-7', |
||
| 393 | 'CSUNICODE11UTF7', |
||
| 394 | 'UCS-2-INTERNAL', |
||
| 395 | 'UCS-2-SWAPPED', |
||
| 396 | 'UCS-4-INTERNAL', |
||
| 397 | 'UCS-4-SWAPPED', |
||
| 398 | 'C99', |
||
| 399 | 'JAVA', |
||
| 400 | 'CP819', |
||
| 401 | 'IBM819', |
||
| 402 | 'ISO-8859-1', |
||
| 403 | 'ISO-IR-100', |
||
| 404 | 'ISO8859-1', |
||
| 405 | 'ISO_8859-1', |
||
| 406 | 'ISO_8859-1:1987', |
||
| 407 | 'L1', |
||
| 408 | 'LATIN1', |
||
| 409 | 'CSISOLATIN1', |
||
| 410 | 'ISO-8859-2', |
||
| 411 | 'ISO-IR-101', |
||
| 412 | 'ISO8859-2', |
||
| 413 | 'ISO_8859-2', |
||
| 414 | 'ISO_8859-2:1987', |
||
| 415 | 'L2', |
||
| 416 | 'LATIN2', |
||
| 417 | 'CSISOLATIN2', |
||
| 418 | 'ISO-8859-3', |
||
| 419 | 'ISO-IR-109', |
||
| 420 | 'ISO8859-3', |
||
| 421 | 'ISO_8859-3', |
||
| 422 | 'ISO_8859-3:1988', |
||
| 423 | 'L3', |
||
| 424 | 'LATIN3', |
||
| 425 | 'CSISOLATIN3', |
||
| 426 | 'ISO-8859-4', |
||
| 427 | 'ISO-IR-110', |
||
| 428 | 'ISO8859-4', |
||
| 429 | 'ISO_8859-4', |
||
| 430 | 'ISO_8859-4:1988', |
||
| 431 | 'L4', |
||
| 432 | 'LATIN4', |
||
| 433 | 'CSISOLATIN4', |
||
| 434 | 'CYRILLIC', |
||
| 435 | 'ISO-8859-5', |
||
| 436 | 'ISO-IR-144', |
||
| 437 | 'ISO8859-5', |
||
| 438 | 'ISO_8859-5', |
||
| 439 | 'ISO_8859-5:1988', |
||
| 440 | 'CSISOLATINCYRILLIC', |
||
| 441 | 'ARABIC', |
||
| 442 | 'ASMO-708', |
||
| 443 | 'ECMA-114', |
||
| 444 | 'ISO-8859-6', |
||
| 445 | 'ISO-IR-127', |
||
| 446 | 'ISO8859-6', |
||
| 447 | 'ISO_8859-6', |
||
| 448 | 'ISO_8859-6:1987', |
||
| 449 | 'CSISOLATINARABIC', |
||
| 450 | 'ECMA-118', |
||
| 451 | 'ELOT_928', |
||
| 452 | 'GREEK', |
||
| 453 | 'GREEK8', |
||
| 454 | 'ISO-8859-7', |
||
| 455 | 'ISO-IR-126', |
||
| 456 | 'ISO8859-7', |
||
| 457 | 'ISO_8859-7', |
||
| 458 | 'ISO_8859-7:1987', |
||
| 459 | 'ISO_8859-7:2003', |
||
| 460 | 'CSISOLATINGREEK', |
||
| 461 | 'HEBREW', |
||
| 462 | 'ISO-8859-8', |
||
| 463 | 'ISO-IR-138', |
||
| 464 | 'ISO8859-8', |
||
| 465 | 'ISO_8859-8', |
||
| 466 | 'ISO_8859-8:1988', |
||
| 467 | 'CSISOLATINHEBREW', |
||
| 468 | 'ISO-8859-9', |
||
| 469 | 'ISO-IR-148', |
||
| 470 | 'ISO8859-9', |
||
| 471 | 'ISO_8859-9', |
||
| 472 | 'ISO_8859-9:1989', |
||
| 473 | 'L5', |
||
| 474 | 'LATIN5', |
||
| 475 | 'CSISOLATIN5', |
||
| 476 | 'ISO-8859-10', |
||
| 477 | 'ISO-IR-157', |
||
| 478 | 'ISO8859-10', |
||
| 479 | 'ISO_8859-10', |
||
| 480 | 'ISO_8859-10:1992', |
||
| 481 | 'L6', |
||
| 482 | 'LATIN6', |
||
| 483 | 'CSISOLATIN6', |
||
| 484 | 'ISO-8859-11', |
||
| 485 | 'ISO8859-11', |
||
| 486 | 'ISO_8859-11', |
||
| 487 | 'ISO-8859-13', |
||
| 488 | 'ISO-IR-179', |
||
| 489 | 'ISO8859-13', |
||
| 490 | 'ISO_8859-13', |
||
| 491 | 'L7', |
||
| 492 | 'LATIN7', |
||
| 493 | 'ISO-8859-14', |
||
| 494 | 'ISO-CELTIC', |
||
| 495 | 'ISO-IR-199', |
||
| 496 | 'ISO8859-14', |
||
| 497 | 'ISO_8859-14', |
||
| 498 | 'ISO_8859-14:1998', |
||
| 499 | 'L8', |
||
| 500 | 'LATIN8', |
||
| 501 | 'ISO-8859-15', |
||
| 502 | 'ISO-IR-203', |
||
| 503 | 'ISO8859-15', |
||
| 504 | 'ISO_8859-15', |
||
| 505 | 'ISO_8859-15:1998', |
||
| 506 | 'LATIN-9', |
||
| 507 | 'ISO-8859-16', |
||
| 508 | 'ISO-IR-226', |
||
| 509 | 'ISO8859-16', |
||
| 510 | 'ISO_8859-16', |
||
| 511 | 'ISO_8859-16:2001', |
||
| 512 | 'L10', |
||
| 513 | 'LATIN10', |
||
| 514 | 'KOI8-R', |
||
| 515 | 'CSKOI8R', |
||
| 516 | 'KOI8-U', |
||
| 517 | 'KOI8-RU', |
||
| 518 | 'CP1250', |
||
| 519 | 'MS-EE', |
||
| 520 | 'WINDOWS-1250', |
||
| 521 | 'CP1251', |
||
| 522 | 'MS-CYRL', |
||
| 523 | 'WINDOWS-1251', |
||
| 524 | 'CP1252', |
||
| 525 | 'MS-ANSI', |
||
| 526 | 'WINDOWS-1252', |
||
| 527 | 'CP1253', |
||
| 528 | 'MS-GREEK', |
||
| 529 | 'WINDOWS-1253', |
||
| 530 | 'CP1254', |
||
| 531 | 'MS-TURK', |
||
| 532 | 'WINDOWS-1254', |
||
| 533 | 'CP1255', |
||
| 534 | 'MS-HEBR', |
||
| 535 | 'WINDOWS-1255', |
||
| 536 | 'CP1256', |
||
| 537 | 'MS-ARAB', |
||
| 538 | 'WINDOWS-1256', |
||
| 539 | 'CP1257', |
||
| 540 | 'WINBALTRIM', |
||
| 541 | 'WINDOWS-1257', |
||
| 542 | 'CP1258', |
||
| 543 | 'WINDOWS-1258', |
||
| 544 | '850', |
||
| 545 | 'CP850', |
||
| 546 | 'IBM850', |
||
| 547 | 'CSPC850MULTILINGUAL', |
||
| 548 | '862', |
||
| 549 | 'CP862', |
||
| 550 | 'IBM862', |
||
| 551 | 'CSPC862LATINHEBREW', |
||
| 552 | '866', |
||
| 553 | 'CP866', |
||
| 554 | 'IBM866', |
||
| 555 | 'CSIBM866', |
||
| 556 | 'MAC', |
||
| 557 | 'MACINTOSH', |
||
| 558 | 'MACROMAN', |
||
| 559 | 'CSMACINTOSH', |
||
| 560 | 'MACCENTRALEUROPE', |
||
| 561 | 'MACICELAND', |
||
| 562 | 'MACCROATIAN', |
||
| 563 | 'MACROMANIA', |
||
| 564 | 'MACCYRILLIC', |
||
| 565 | 'MACUKRAINE', |
||
| 566 | 'MACGREEK', |
||
| 567 | 'MACTURKISH', |
||
| 568 | 'MACHEBREW', |
||
| 569 | 'MACARABIC', |
||
| 570 | 'MACTHAI', |
||
| 571 | 'HP-ROMAN8', |
||
| 572 | 'R8', |
||
| 573 | 'ROMAN8', |
||
| 574 | 'CSHPROMAN8', |
||
| 575 | 'NEXTSTEP', |
||
| 576 | 'ARMSCII-8', |
||
| 577 | 'GEORGIAN-ACADEMY', |
||
| 578 | 'GEORGIAN-PS', |
||
| 579 | 'KOI8-T', |
||
| 580 | 'CP154', |
||
| 581 | 'CYRILLIC-ASIAN', |
||
| 582 | 'PT154', |
||
| 583 | 'PTCP154', |
||
| 584 | 'CSPTCP154', |
||
| 585 | 'KZ-1048', |
||
| 586 | 'RK1048', |
||
| 587 | 'STRK1048-2002', |
||
| 588 | 'CSKZ1048', |
||
| 589 | 'MULELAO-1', |
||
| 590 | 'CP1133', |
||
| 591 | 'IBM-CP1133', |
||
| 592 | 'ISO-IR-166', |
||
| 593 | 'TIS-620', |
||
| 594 | 'TIS620', |
||
| 595 | 'TIS620-0', |
||
| 596 | 'TIS620.2529-1', |
||
| 597 | 'TIS620.2533-0', |
||
| 598 | 'TIS620.2533-1', |
||
| 599 | 'CP874', |
||
| 600 | 'WINDOWS-874', |
||
| 601 | 'VISCII', |
||
| 602 | 'VISCII1.1-1', |
||
| 603 | 'CSVISCII', |
||
| 604 | 'TCVN', |
||
| 605 | 'TCVN-5712', |
||
| 606 | 'TCVN5712-1', |
||
| 607 | 'TCVN5712-1:1993', |
||
| 608 | 'ISO-IR-14', |
||
| 609 | 'ISO646-JP', |
||
| 610 | 'JIS_C6220-1969-RO', |
||
| 611 | 'JP', |
||
| 612 | 'CSISO14JISC6220RO', |
||
| 613 | 'JISX0201-1976', |
||
| 614 | 'JIS_X0201', |
||
| 615 | 'X0201', |
||
| 616 | 'CSHALFWIDTHKATAKANA', |
||
| 617 | 'ISO-IR-87', |
||
| 618 | 'JIS0208', |
||
| 619 | 'JIS_C6226-1983', |
||
| 620 | 'JIS_X0208', |
||
| 621 | 'JIS_X0208-1983', |
||
| 622 | 'JIS_X0208-1990', |
||
| 623 | 'X0208', |
||
| 624 | 'CSISO87JISX0208', |
||
| 625 | 'ISO-IR-159', |
||
| 626 | 'JIS_X0212', |
||
| 627 | 'JIS_X0212-1990', |
||
| 628 | 'JIS_X0212.1990-0', |
||
| 629 | 'X0212', |
||
| 630 | 'CSISO159JISX02121990', |
||
| 631 | 'CN', |
||
| 632 | 'GB_1988-80', |
||
| 633 | 'ISO-IR-57', |
||
| 634 | 'ISO646-CN', |
||
| 635 | 'CSISO57GB1988', |
||
| 636 | 'CHINESE', |
||
| 637 | 'GB_2312-80', |
||
| 638 | 'ISO-IR-58', |
||
| 639 | 'CSISO58GB231280', |
||
| 640 | 'CN-GB-ISOIR165', |
||
| 641 | 'ISO-IR-165', |
||
| 642 | 'ISO-IR-149', |
||
| 643 | 'KOREAN', |
||
| 644 | 'KSC_5601', |
||
| 645 | 'KS_C_5601-1987', |
||
| 646 | 'KS_C_5601-1989', |
||
| 647 | 'CSKSC56011987', |
||
| 648 | 'EUC-JP', |
||
| 649 | 'EUCJP', |
||
| 650 | 'EXTENDED_UNIX_CODE_PACKED_FORMAT_FOR_JAPANESE', |
||
| 651 | 'CSEUCPKDFMTJAPANESE', |
||
| 652 | 'MS_KANJI', |
||
| 653 | 'SHIFT-JIS', |
||
| 654 | 'SHIFT_JIS', |
||
| 655 | 'SJIS', |
||
| 656 | 'CSSHIFTJIS', |
||
| 657 | 'CP932', |
||
| 658 | 'ISO-2022-JP', |
||
| 659 | 'CSISO2022JP', |
||
| 660 | 'ISO-2022-JP-1', |
||
| 661 | 'ISO-2022-JP-2', |
||
| 662 | 'CSISO2022JP2', |
||
| 663 | 'CN-GB', |
||
| 664 | 'EUC-CN', |
||
| 665 | 'EUCCN', |
||
| 666 | 'GB2312', |
||
| 667 | 'CSGB2312', |
||
| 668 | 'GBK', |
||
| 669 | 'CP936', |
||
| 670 | 'MS936', |
||
| 671 | 'WINDOWS-936', |
||
| 672 | 'GB18030', |
||
| 673 | 'ISO-2022-CN', |
||
| 674 | 'CSISO2022CN', |
||
| 675 | 'ISO-2022-CN-EXT', |
||
| 676 | 'HZ', |
||
| 677 | 'HZ-GB-2312', |
||
| 678 | 'EUC-TW', |
||
| 679 | 'EUCTW', |
||
| 680 | 'CSEUCTW', |
||
| 681 | 'BIG-5', |
||
| 682 | 'BIG-FIVE', |
||
| 683 | 'BIG5', |
||
| 684 | 'BIGFIVE', |
||
| 685 | 'CN-BIG5', |
||
| 686 | 'CSBIG5', |
||
| 687 | 'CP950', |
||
| 688 | 'BIG5-HKSCS:1999', |
||
| 689 | 'BIG5-HKSCS:2001', |
||
| 690 | 'BIG5-HKSCS', |
||
| 691 | 'BIG5-HKSCS:2004', |
||
| 692 | 'BIG5HKSCS', |
||
| 693 | 'EUC-KR', |
||
| 694 | 'EUCKR', |
||
| 695 | 'CSEUCKR', |
||
| 696 | 'CP949', |
||
| 697 | 'UHC', |
||
| 698 | 'CP1361', |
||
| 699 | 'JOHAB', |
||
| 700 | 'ISO-2022-KR', |
||
| 701 | 'CSISO2022KR', |
||
| 702 | 'CP856', |
||
| 703 | 'CP922', |
||
| 704 | 'CP943', |
||
| 705 | 'CP1046', |
||
| 706 | 'CP1124', |
||
| 707 | 'CP1129', |
||
| 708 | 'CP1161', |
||
| 709 | 'IBM-1161', |
||
| 710 | 'IBM1161', |
||
| 711 | 'CSIBM1161', |
||
| 712 | 'CP1162', |
||
| 713 | 'IBM-1162', |
||
| 714 | 'IBM1162', |
||
| 715 | 'CSIBM1162', |
||
| 716 | 'CP1163', |
||
| 717 | 'IBM-1163', |
||
| 718 | 'IBM1163', |
||
| 719 | 'CSIBM1163', |
||
| 720 | 'DEC-KANJI', |
||
| 721 | 'DEC-HANYU', |
||
| 722 | '437', |
||
| 723 | 'CP437', |
||
| 724 | 'IBM437', |
||
| 725 | 'CSPC8CODEPAGE437', |
||
| 726 | 'CP737', |
||
| 727 | 'CP775', |
||
| 728 | 'IBM775', |
||
| 729 | 'CSPC775BALTIC', |
||
| 730 | '852', |
||
| 731 | 'CP852', |
||
| 732 | 'IBM852', |
||
| 733 | 'CSPCP852', |
||
| 734 | 'CP853', |
||
| 735 | '855', |
||
| 736 | 'CP855', |
||
| 737 | 'IBM855', |
||
| 738 | 'CSIBM855', |
||
| 739 | '857', |
||
| 740 | 'CP857', |
||
| 741 | 'IBM857', |
||
| 742 | 'CSIBM857', |
||
| 743 | 'CP858', |
||
| 744 | '860', |
||
| 745 | 'CP860', |
||
| 746 | 'IBM860', |
||
| 747 | 'CSIBM860', |
||
| 748 | '861', |
||
| 749 | 'CP-IS', |
||
| 750 | 'CP861', |
||
| 751 | 'IBM861', |
||
| 752 | 'CSIBM861', |
||
| 753 | '863', |
||
| 754 | 'CP863', |
||
| 755 | 'IBM863', |
||
| 756 | 'CSIBM863', |
||
| 757 | 'CP864', |
||
| 758 | 'IBM864', |
||
| 759 | 'CSIBM864', |
||
| 760 | '865', |
||
| 761 | 'CP865', |
||
| 762 | 'IBM865', |
||
| 763 | 'CSIBM865', |
||
| 764 | '869', |
||
| 765 | 'CP-GR', |
||
| 766 | 'CP869', |
||
| 767 | 'IBM869', |
||
| 768 | 'CSIBM869', |
||
| 769 | 'CP1125', |
||
| 770 | 'EUC-JISX0213', |
||
| 771 | 'SHIFT_JISX0213', |
||
| 772 | 'ISO-2022-JP-3', |
||
| 773 | 'BIG5-2003', |
||
| 774 | 'ISO-IR-230', |
||
| 775 | 'TDS565', |
||
| 776 | 'ATARI', |
||
| 777 | 'ATARIST', |
||
| 778 | 'RISCOS-LATIN1', |
||
| 779 | ); |
||
| 780 | |||
| 781 | /** |
||
| 782 | * @var array |
||
| 783 | */ |
||
| 784 | private static $support = array(); |
||
| 785 | |||
| 786 | /** |
||
| 787 | * __construct() |
||
| 788 | */ |
||
| 789 | public function __construct() |
||
| 790 | 1 | { |
|
| 791 | self::checkForSupport(); |
||
| 792 | 1 | } |
|
| 793 | 1 | ||
| 794 | /** |
||
| 795 | * Returns a single UTF-8 character from string. |
||
| 796 | * |
||
| 797 | * @param string $str A UTF-8 string. |
||
| 798 | * @param int $pos The position of character to return. |
||
| 799 | * |
||
| 800 | * @return string Single Multi-Byte character. |
||
| 801 | */ |
||
| 802 | public static function access($str, $pos) |
||
| 808 | |||
| 809 | /** |
||
| 810 | * Prepends BOM character to the string and returns the whole string. |
||
| 811 | * |
||
| 812 | * INFO: If BOM already existed there, the Input string is returned. |
||
| 813 | * |
||
| 814 | * @param string $str The input string |
||
| 815 | * |
||
| 816 | * @return string The output string that contains BOM |
||
| 817 | */ |
||
| 818 | public static function add_bom_to_string($str) |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Returns the Byte Order Mark Character. |
||
| 829 | * |
||
| 830 | * @return string Byte Order Mark |
||
| 831 | */ |
||
| 832 | public static function bom() |
||
| 836 | |||
| 837 | /** |
||
| 838 | * @alias of UTF8::chr_map() |
||
| 839 | * |
||
| 840 | * @param $callback |
||
| 841 | * @param $str |
||
| 842 | * |
||
| 843 | * @return array |
||
| 844 | */ |
||
| 845 | public static function callback($callback, $str) |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Returns an array of all lower and upper case UTF-8 encoded characters. |
||
| 852 | * |
||
| 853 | * @return string An array with lower case chars as keys and upper chars as values. |
||
| 854 | */ |
||
| 855 | protected static function case_table() |
||
| 1856 | |||
| 1857 | /** |
||
| 1858 | * check for UTF8-Support |
||
| 1859 | */ |
||
| 1860 | public static function checkForSupport() |
||
| 1861 | 157 | { |
|
| 1862 | if (!isset(self::$support['mbstring'])) { |
||
| 1863 | 157 | ||
| 1864 | self::$support['mbstring'] = self::mbstring_loaded(); |
||
| 1865 | 1 | self::$support['iconv'] = self::iconv_loaded(); |
|
| 1866 | 1 | self::$support['intl'] = self::intl_loaded(); |
|
| 1867 | 1 | self::$support['intlChar'] = self::intlChar_loaded(); |
|
| 1868 | 1 | self::$support['pcre_utf8'] = self::pcre_utf8_support(); |
|
| 1869 | 1 | } |
|
| 1870 | 157 | } |
|
| 1871 | |||
| 1872 | /** |
||
| 1873 | * Generates a UTF-8 encoded character from the given code point. |
||
| 1874 | * |
||
| 1875 | * @param int $code_point The code point for which to generate a character. |
||
| 1876 | * |
||
| 1877 | * @return string Multi-Byte character, returns empty string on failure to encode. |
||
| 1878 | */ |
||
| 1879 | 8 | public static function chr($code_point) |
|
| 1899 | |||
| 1900 | /** |
||
| 1901 | * Applies callback to all characters of a string. |
||
| 1902 | 1 | * |
|
| 1903 | * @param string $callback The callback function. |
||
| 1904 | 1 | * @param string $str UTF-8 string to run callback on. |
|
| 1905 | * |
||
| 1906 | 1 | * @return array The outcome of callback. |
|
| 1907 | */ |
||
| 1908 | |||
| 1909 | public static function chr_map($callback, $str) |
||
| 1915 | |||
| 1916 | /** |
||
| 1917 | * Generates an array of byte length of each character of a Unicode string. |
||
| 1918 | * |
||
| 1919 | * 1 byte => U+0000 - U+007F |
||
| 1920 | * 2 byte => U+0080 - U+07FF |
||
| 1921 | 2 | * 3 byte => U+0800 - U+FFFF |
|
| 1922 | * 4 byte => U+10000 - U+10FFFF |
||
| 1923 | 2 | * |
|
| 1924 | 2 | * @param string $str The original Unicode string. |
|
| 1925 | * |
||
| 1926 | * @return array An array of byte lengths of each character. |
||
| 1927 | 2 | */ |
|
| 1928 | public static function chr_size_list($str) |
||
| 1936 | |||
| 1937 | 2 | /** |
|
| 1938 | * Get a decimal code representation of a specific character. |
||
| 1939 | 2 | * |
|
| 1940 | 2 | * @param string $chr The input character |
|
| 1941 | 2 | * |
|
| 1942 | * @return int |
||
| 1943 | 2 | */ |
|
| 1944 | public static function chr_to_decimal($chr) |
||
| 1976 | |||
| 1977 | /** |
||
| 1978 | * Get hexadecimal code point (U+xxxx) of a UTF-8 encoded character. |
||
| 1979 | * |
||
| 1980 | * @param string $chr The input character |
||
| 1981 | * @param string $pfix |
||
| 1982 | * |
||
| 1983 | * @return string The code point encoded as U+xxxx |
||
| 1984 | */ |
||
| 1985 | public static function chr_to_hex($chr, $pfix = 'U+') |
||
| 1989 | |||
| 1990 | /** |
||
| 1991 | * Splits a string into smaller chunks and multiple lines, using the specified |
||
| 1992 | * line ending character. |
||
| 1993 | 1 | * |
|
| 1994 | * @param string $body The original string to be split. |
||
| 1995 | 1 | * @param int $chunklen The maximum character length of a chunk. |
|
| 1996 | * @param string $end The character(s) to be inserted at the end of each chunk. |
||
| 1997 | * |
||
| 1998 | * @return string The chunked string |
||
| 1999 | */ |
||
| 2000 | public static function chunk_split($body, $chunklen = 76, $end = "\r\n") |
||
| 2004 | |||
| 2005 | /** |
||
| 2006 | * accepts a string and removes all non-UTF-8 characters from it. |
||
| 2007 | * |
||
| 2008 | * @param string $str The string to be sanitized. |
||
| 2009 | 35 | * @param bool $remove_bom |
|
| 2010 | * @param bool $normalize_whitespace |
||
| 2011 | * @param bool $normalize_msword e.g.: "…" => "..." |
||
| 2012 | * @param bool $keep_non_breaking_space set true, to keep non-breaking-spaces |
||
| 2013 | * |
||
| 2014 | * @return string Clean UTF-8 encoded string |
||
| 2015 | */ |
||
| 2016 | public static function clean($str, $remove_bom = false, $normalize_whitespace = false, $normalize_msword = false, $keep_non_breaking_space = false) |
||
| 2051 | |||
| 2052 | 3 | /** |
|
| 2053 | * Clean-up a and show only printable UTF-8 chars at the end. |
||
| 2054 | 3 | * |
|
| 2055 | * @param string $str |
||
| 2056 | 3 | * |
|
| 2057 | 1 | * @return string |
|
| 2058 | */ |
||
| 2059 | public static function cleanup($str) |
||
| 2079 | |||
| 2080 | /** |
||
| 2081 | * Accepts a string and returns an array of Unicode code points. |
||
| 2082 | 3 | * |
|
| 2083 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
||
| 2084 | 3 | * @param bool $u_style If True, will return code points in U+xxxx format, |
|
| 2085 | 3 | * default, code points will be returned as integers. |
|
| 2086 | 3 | * |
|
| 2087 | * @return array The array of code points |
||
| 2088 | 3 | */ |
|
| 2089 | public static function codepoints($arg, $u_style = false) |
||
| 2115 | |||
| 2116 | /** |
||
| 2117 | 3 | * Returns count of characters used in a string. |
|
| 2118 | * |
||
| 2119 | 3 | * @param string $str The input string. |
|
| 2120 | * |
||
| 2121 | 3 | * @return array An associative array of Character as keys and |
|
| 2122 | * their count as values. |
||
| 2123 | 3 | */ |
|
| 2124 | public static function count_chars($str) // there is no $mode parameters |
||
| 2132 | |||
| 2133 | 1 | /** |
|
| 2134 | * Get a UTF-8 character from its decimal code representation. |
||
| 2135 | 1 | * |
|
| 2136 | * @param int $code Code. |
||
| 2137 | 1 | * |
|
| 2138 | 1 | * @return string |
|
| 2139 | 1 | */ |
|
| 2140 | public static function decimal_to_chr($code) |
||
| 2150 | |||
| 2151 | /** |
||
| 2152 | * encode a string |
||
| 2153 | * |
||
| 2154 | * INFO: The different to "UTF8::utf8_encode()" is that this function, try to fix also broken / double encoding, |
||
| 2155 | 11 | * so you can call this function also on a UTF-8 String and you don't mess the string. |
|
| 2156 | * |
||
| 2157 | 11 | * @param string $encoding e.g. 'UTF-8', 'ISO-8859-1', etc. |
|
| 2158 | * @param string $str the string |
||
| 2159 | 11 | * @param bool $force force the new encoding (we try to fix broken / double encoding for UTF-8)<br /> |
|
| 2160 | 11 | * otherwise we auto-detect the current string-encoding |
|
| 2161 | * |
||
| 2162 | * @return string |
||
| 2163 | 1 | */ |
|
| 2164 | 1 | public static function encode($encoding, $str, $force = true) |
|
| 2225 | |||
| 2226 | /** |
||
| 2227 | * Callback function for preg_replace_callback use. |
||
| 2228 | * |
||
| 2229 | * @param array $matches PREG matches |
||
| 2230 | * |
||
| 2231 | * @return string |
||
| 2232 | */ |
||
| 2233 | protected static function entityCallback($matches) |
||
| 2245 | |||
| 2246 | /** |
||
| 2247 | * Reads entire file into a string. |
||
| 2248 | * |
||
| 2249 | * WARNING: do not use UTF-8 Option fir binary-files (e.g.: images) !!! |
||
| 2250 | * |
||
| 2251 | * @link http://php.net/manual/en/function.file-get-contents.php |
||
| 2252 | 2 | * |
|
| 2253 | * @param string $filename <p> |
||
| 2254 | * Name of the file to read. |
||
| 2255 | 2 | * </p> |
|
| 2256 | 2 | * @param int $flags [optional] <p> |
|
| 2257 | * Prior to PHP 6, this parameter is called |
||
| 2258 | 2 | * use_include_path and is a bool. |
|
| 2259 | 2 | * As of PHP 5 the FILE_USE_INCLUDE_PATH can be used |
|
| 2260 | * to trigger include path |
||
| 2261 | * search. |
||
| 2262 | * </p> |
||
| 2263 | 2 | * <p> |
|
| 2264 | 2 | * The value of flags can be any combination of |
|
| 2265 | * the following flags (with some restrictions), joined with the |
||
| 2266 | 2 | * binary OR (|) |
|
| 2267 | 2 | * operator. |
|
| 2268 | * </p> |
||
| 2269 | 2 | * <p> |
|
| 2270 | 1 | * <table> |
|
| 2271 | 1 | * Available flags |
|
| 2272 | 2 | * <tr valign="top"> |
|
| 2273 | * <td>Flag</td> |
||
| 2274 | * <td>Description</td> |
||
| 2275 | * </tr> |
||
| 2276 | 2 | * <tr valign="top"> |
|
| 2277 | * <td> |
||
| 2278 | * FILE_USE_INCLUDE_PATH |
||
| 2279 | * </td> |
||
| 2280 | 2 | * <td> |
|
| 2281 | 2 | * Search for filename in the include directory. |
|
| 2282 | * See include_path for more |
||
| 2283 | 2 | * information. |
|
| 2284 | * </td> |
||
| 2285 | 2 | * </tr> |
|
| 2286 | 1 | * <tr valign="top"> |
|
| 2287 | 1 | * <td> |
|
| 2288 | 1 | * FILE_TEXT |
|
| 2289 | 1 | * </td> |
|
| 2290 | 1 | * <td> |
|
| 2291 | 1 | * As of PHP 6, the default encoding of the read |
|
| 2292 | * data is UTF-8. You can specify a different encoding by creating a |
||
| 2293 | 2 | * custom context or by changing the default using |
|
| 2294 | 2 | * stream_default_encoding. This flag cannot be |
|
| 2295 | 2 | * used with FILE_BINARY. |
|
| 2296 | 2 | * </td> |
|
| 2297 | * </tr> |
||
| 2298 | * <tr valign="top"> |
||
| 2299 | 2 | * <td> |
|
| 2300 | * FILE_BINARY |
||
| 2301 | * </td> |
||
| 2302 | * <td> |
||
| 2303 | * With this flag, the file is read in binary mode. This is the default |
||
| 2304 | * setting and cannot be used with FILE_TEXT. |
||
| 2305 | * </td> |
||
| 2306 | * </tr> |
||
| 2307 | * </table> |
||
| 2308 | * </p> |
||
| 2309 | 1 | * @param resource $context [optional] <p> |
|
| 2310 | * A valid context resource created with |
||
| 2311 | 1 | * stream_context_create. If you don't need to use a |
|
| 2312 | * custom context, you can skip this parameter by &null;. |
||
| 2313 | * </p> |
||
| 2314 | * @param int $offset [optional] <p> |
||
| 2315 | * The offset where the reading starts. |
||
| 2316 | * </p> |
||
| 2317 | * @param int $maxlen [optional] <p> |
||
| 2318 | * Maximum length of data read. The default is to read until end |
||
| 2319 | * of file is reached. |
||
| 2320 | * </p> |
||
| 2321 | * @param int $timeout |
||
| 2322 | * |
||
| 2323 | 7 | * @param boolean $convertToUtf8 WARNING: maybe you can't use this option for images or pdf, because they used non |
|
| 2324 | * default utf-8 chars |
||
| 2325 | 7 | * |
|
| 2326 | 7 | * @return string The function returns the read data or false on failure. |
|
| 2327 | 2 | */ |
|
| 2328 | public static function file_get_contents($filename, $flags = null, $context = null, $offset = null, $maxlen = null, $timeout = 10, $convertToUtf8 = true) |
||
| 2366 | |||
| 2367 | /** |
||
| 2368 | * Checks if a file starts with BOM character. |
||
| 2369 | * |
||
| 2370 | * @param string $file_path Path to a valid file. |
||
| 2371 | * |
||
| 2372 | * @return bool True if the file has BOM at the start, False otherwise. |
||
| 2373 | */ |
||
| 2374 | public static function file_has_bom($file_path) |
||
| 2378 | |||
| 2379 | /** |
||
| 2380 | * Normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 2381 | * |
||
| 2382 | * @param mixed $var |
||
| 2383 | * @param int $normalization_form |
||
| 2384 | * @param string $leading_combining |
||
| 2385 | * |
||
| 2386 | * @return mixed |
||
| 2387 | */ |
||
| 2388 | public static function filter($var, $normalization_form = 4, $leading_combining = '◌') |
||
| 2431 | |||
| 2432 | /** |
||
| 2433 | * "filter_input()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 2434 | * |
||
| 2435 | * @param int $type |
||
| 2436 | * @param string $var |
||
| 2437 | 1 | * @param int $filter |
|
| 2438 | * @param mixed $option |
||
| 2439 | 1 | * |
|
| 2440 | 1 | * @return mixed |
|
| 2441 | 1 | */ |
|
| 2442 | 1 | View Code Duplication | public static function filter_input($type, $var, $filter = FILTER_DEFAULT, $option = null) |
| 2452 | |||
| 2453 | /** |
||
| 2454 | * "filter_input_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 2455 | * |
||
| 2456 | * @param int $type |
||
| 2457 | 1 | * @param mixed $definition |
|
| 2458 | * @param bool $add_empty |
||
| 2459 | 1 | * |
|
| 2460 | * @return mixed |
||
| 2461 | */ |
||
| 2462 | View Code Duplication | public static function filter_input_array($type, $definition = null, $add_empty = true) |
|
| 2463 | { |
||
| 2464 | if (2 > func_num_args()) { |
||
| 2465 | $a = filter_input_array($type); |
||
| 2466 | } else { |
||
| 2467 | $a = filter_input_array($type, $definition, $add_empty); |
||
| 2468 | } |
||
| 2469 | 8 | ||
| 2470 | return self::filter($a); |
||
| 2471 | 8 | } |
|
| 2472 | 8 | ||
| 2473 | /** |
||
| 2474 | 8 | * "filter_var()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
|
| 2475 | * |
||
| 2476 | 8 | * @param mixed $var |
|
| 2477 | 2 | * @param int $filter |
|
| 2478 | * @param mixed $option |
||
| 2479 | * |
||
| 2480 | 8 | * @return mixed |
|
| 2481 | 1 | */ |
|
| 2482 | 1 | View Code Duplication | public static function filter_var($var, $filter = FILTER_DEFAULT, $option = null) |
| 2492 | |||
| 2493 | /** |
||
| 2494 | * "filter_var_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 2495 | 1 | * |
|
| 2496 | * @param array $data |
||
| 2497 | 1 | * @param mixed $definition |
|
| 2498 | * @param bool $add_empty |
||
| 2499 | * |
||
| 2500 | * @return mixed |
||
| 2501 | */ |
||
| 2502 | View Code Duplication | public static function filter_var_array($data, $definition = null, $add_empty = true) |
|
| 2512 | |||
| 2513 | 1 | /** |
|
| 2514 | * Checks if the number of Unicode characters in a string are not |
||
| 2515 | * more than the specified integer. |
||
| 2516 | * |
||
| 2517 | * @param string $str The original string to be checked. |
||
| 2518 | * @param int $box_size The size in number of chars to be checked against string. |
||
| 2519 | * |
||
| 2520 | * @return bool true if string is less than or equal to $box_size, false otherwise. |
||
| 2521 | */ |
||
| 2522 | public static function fits_inside($str, $box_size) |
||
| 2526 | |||
| 2527 | 1 | /** |
|
| 2528 | 1 | * Fixing a broken UTF-8 string. |
|
| 2529 | * |
||
| 2530 | * @param string $str |
||
| 2531 | 1 | * |
|
| 2532 | * @return string |
||
| 2533 | 1 | */ |
|
| 2534 | 1 | public static function fix_simple_utf8($str) |
|
| 2535 | 1 | { |
|
| 2536 | 1 | static $brokenUtf8ToUtf8Keys = null; |
|
| 2537 | 1 | static $brokenUtf8ToUtf8Values = null; |
|
| 2538 | 1 | ||
| 2539 | 1 | $str = (string)$str; |
|
| 2540 | 1 | ||
| 2541 | 1 | if (!isset($str[0])) { |
|
| 2542 | 1 | return ''; |
|
| 2543 | 1 | } |
|
| 2544 | |||
| 2545 | if ($brokenUtf8ToUtf8Keys === null) { |
||
| 2546 | $brokenUtf8ToUtf8Keys = array_keys(self::$brokenUtf8ToUtf8); |
||
| 2547 | $brokenUtf8ToUtf8Values = array_values(self::$brokenUtf8ToUtf8); |
||
| 2548 | } |
||
| 2549 | |||
| 2550 | return str_replace($brokenUtf8ToUtf8Keys, $brokenUtf8ToUtf8Values, $str); |
||
| 2551 | } |
||
| 2552 | |||
| 2553 | /** |
||
| 2554 | * Fix a double (or multiple) encoded UTF8 string. |
||
| 2555 | * |
||
| 2556 | * @param array|string $str |
||
| 2557 | * |
||
| 2558 | * @return string |
||
| 2559 | */ |
||
| 2560 | public static function fix_utf8($str) |
||
| 2580 | |||
| 2581 | /** |
||
| 2582 | * Get character of a specific character. |
||
| 2583 | * |
||
| 2584 | * @param string $char Character. |
||
| 2585 | * |
||
| 2586 | * @return string 'RTL' or 'LTR' |
||
| 2587 | */ |
||
| 2588 | public static function getCharDirection($char) |
||
| 2699 | |||
| 2700 | /** |
||
| 2701 | * get data from "/data/*.ser" |
||
| 2702 | * |
||
| 2703 | * @param string $file |
||
| 2704 | * |
||
| 2705 | * @return bool|string|array|int false on error |
||
| 2706 | */ |
||
| 2707 | protected static function getData($file) |
||
| 2717 | 1 | ||
| 2718 | 1 | /** |
|
| 2719 | * Creates a random string of UTF-8 characters. |
||
| 2720 | * |
||
| 2721 | * @param int $len The length of string in characters. |
||
| 2722 | * |
||
| 2723 | * @return string String consisting of random characters. |
||
| 2724 | */ |
||
| 2725 | public static function hash($len = 8) |
||
| 2765 | |||
| 2766 | /** |
||
| 2767 | * Converts hexadecimal U+xxxx code point representation to Integer. |
||
| 2768 | * |
||
| 2769 | * INFO: opposite to UTF8::int_to_hex( ) |
||
| 2770 | * |
||
| 2771 | * @param string $str The hexadecimal code point representation. |
||
| 2772 | * |
||
| 2773 | * @return int The code point, or 0 on failure. |
||
| 2774 | */ |
||
| 2775 | public static function hex_to_int($str) |
||
| 2783 | |||
| 2784 | /** |
||
| 2785 | * alias for "UTF8::html_entity_decode()" |
||
| 2786 | * |
||
| 2787 | * @param string $str |
||
| 2788 | * @param int $flags |
||
| 2789 | * @param string $encoding |
||
| 2790 | 15 | * |
|
| 2791 | * @return string |
||
| 2792 | 15 | */ |
|
| 2793 | public static function html_decode($str, $flags = null, $encoding = 'UTF-8') |
||
| 2797 | |||
| 2798 | 15 | /** |
|
| 2799 | 4 | * Converts a UTF-8 string to a series of HTML numbered entities. |
|
| 2800 | * |
||
| 2801 | * e.g.: {'ی |
||
| 2802 | 15 | * |
|
| 2803 | 3 | * @param string $str The Unicode string to be encoded as numbered entities. |
|
| 2804 | 3 | * @param bool $keepAsciiChars Keep ASCII chars. |
|
| 2805 | 3 | * |
|
| 2806 | * @return string HTML numbered entities. |
||
| 2807 | */ |
||
| 2808 | 3 | public static function html_encode($str, $keepAsciiChars = false) |
|
| 2834 | 12 | ||
| 2835 | /** |
||
| 2836 | 12 | * UTF-8 version of html_entity_decode() |
|
| 2837 | * |
||
| 2838 | 12 | * The reason we are not using html_entity_decode() by itself is because |
|
| 2839 | * while it is not technically correct to leave out the semicolon |
||
| 2840 | 12 | * at the end of an entity most browsers will still interpret the entity |
|
| 2841 | 5 | * correctly. html_entity_decode() does not convert entities without |
|
| 2842 | * semicolons, so we are left with our own little solution here. Bummer. |
||
| 2843 | * |
||
| 2844 | 11 | * Convert all HTML entities to their applicable characters |
|
| 2845 | * |
||
| 2846 | * @link http://php.net/manual/en/function.html-entity-decode.php |
||
| 2847 | * |
||
| 2848 | * @param string $str <p> |
||
| 2849 | * The input string. |
||
| 2850 | * </p> |
||
| 2851 | * @param int $flags [optional] <p> |
||
| 2852 | * A bitmask of one or more of the following flags, which specify how to handle quotes and |
||
| 2853 | * which document type to use. The default is ENT_COMPAT | ENT_HTML401. |
||
| 2854 | * <table> |
||
| 2855 | * Available <i>flags</i> constants |
||
| 2856 | * <tr valign="top"> |
||
| 2857 | * <td>Constant Name</td> |
||
| 2858 | * <td>Description</td> |
||
| 2859 | * </tr> |
||
| 2860 | * <tr valign="top"> |
||
| 2861 | * <td><b>ENT_COMPAT</b></td> |
||
| 2862 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 2863 | * </tr> |
||
| 2864 | * <tr valign="top"> |
||
| 2865 | * <td><b>ENT_QUOTES</b></td> |
||
| 2866 | * <td>Will convert both double and single quotes.</td> |
||
| 2867 | * </tr> |
||
| 2868 | * <tr valign="top"> |
||
| 2869 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 2870 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 2871 | * </tr> |
||
| 2872 | * <tr valign="top"> |
||
| 2873 | * <td><b>ENT_HTML401</b></td> |
||
| 2874 | * <td> |
||
| 2875 | * Handle code as HTML 4.01. |
||
| 2876 | * </td> |
||
| 2877 | * </tr> |
||
| 2878 | * <tr valign="top"> |
||
| 2879 | * <td><b>ENT_XML1</b></td> |
||
| 2880 | * <td> |
||
| 2881 | * Handle code as XML 1. |
||
| 2882 | * </td> |
||
| 2883 | * </tr> |
||
| 2884 | * <tr valign="top"> |
||
| 2885 | * <td><b>ENT_XHTML</b></td> |
||
| 2886 | * <td> |
||
| 2887 | * Handle code as XHTML. |
||
| 2888 | * </td> |
||
| 2889 | * </tr> |
||
| 2890 | * <tr valign="top"> |
||
| 2891 | * <td><b>ENT_HTML5</b></td> |
||
| 2892 | * <td> |
||
| 2893 | * Handle code as HTML 5. |
||
| 2894 | * </td> |
||
| 2895 | * </tr> |
||
| 2896 | * </table> |
||
| 2897 | * </p> |
||
| 2898 | * @param string $encoding [optional] <p> |
||
| 2899 | * Encoding to use. |
||
| 2900 | * </p> |
||
| 2901 | * |
||
| 2902 | * @return string the decoded string. |
||
| 2903 | */ |
||
| 2904 | public static function html_entity_decode($str, $flags = null, $encoding = 'UTF-8') |
||
| 2940 | |||
| 2941 | /** |
||
| 2942 | * Convert all applicable characters to HTML entities: UTF-8 version of htmlentities() |
||
| 2943 | * |
||
| 2944 | * @link http://php.net/manual/en/function.htmlentities.php |
||
| 2945 | * |
||
| 2946 | * @param string $str <p> |
||
| 2947 | * The input string. |
||
| 2948 | * </p> |
||
| 2949 | * @param int $flags [optional] <p> |
||
| 2950 | 2 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
|
| 2951 | * invalid code unit sequences and the used document type. The default is |
||
| 2952 | 2 | * ENT_COMPAT | ENT_HTML401. |
|
| 2953 | * <table> |
||
| 2954 | * Available <i>flags</i> constants |
||
| 2955 | * <tr valign="top"> |
||
| 2956 | * <td>Constant Name</td> |
||
| 2957 | * <td>Description</td> |
||
| 2958 | * </tr> |
||
| 2959 | * <tr valign="top"> |
||
| 2960 | * <td><b>ENT_COMPAT</b></td> |
||
| 2961 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 2962 | * </tr> |
||
| 2963 | * <tr valign="top"> |
||
| 2964 | * <td><b>ENT_QUOTES</b></td> |
||
| 2965 | * <td>Will convert both double and single quotes.</td> |
||
| 2966 | * </tr> |
||
| 2967 | * <tr valign="top"> |
||
| 2968 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 2969 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 2970 | * </tr> |
||
| 2971 | * <tr valign="top"> |
||
| 2972 | * <td><b>ENT_IGNORE</b></td> |
||
| 2973 | * <td> |
||
| 2974 | * Silently discard invalid code unit sequences instead of returning |
||
| 2975 | * an empty string. Using this flag is discouraged as it |
||
| 2976 | * may have security implications. |
||
| 2977 | * </td> |
||
| 2978 | * </tr> |
||
| 2979 | * <tr valign="top"> |
||
| 2980 | * <td><b>ENT_SUBSTITUTE</b></td> |
||
| 2981 | * <td> |
||
| 2982 | * Replace invalid code unit sequences with a Unicode Replacement Character |
||
| 2983 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
| 2984 | * </td> |
||
| 2985 | * </tr> |
||
| 2986 | * <tr valign="top"> |
||
| 2987 | * <td><b>ENT_DISALLOWED</b></td> |
||
| 2988 | * <td> |
||
| 2989 | * Replace invalid code points for the given document type with a |
||
| 2990 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
| 2991 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
| 2992 | * instance, to ensure the well-formedness of XML documents with |
||
| 2993 | * embedded external content. |
||
| 2994 | * </td> |
||
| 2995 | * </tr> |
||
| 2996 | * <tr valign="top"> |
||
| 2997 | * <td><b>ENT_HTML401</b></td> |
||
| 2998 | * <td> |
||
| 2999 | * Handle code as HTML 4.01. |
||
| 3000 | * </td> |
||
| 3001 | * </tr> |
||
| 3002 | * <tr valign="top"> |
||
| 3003 | * <td><b>ENT_XML1</b></td> |
||
| 3004 | * <td> |
||
| 3005 | * Handle code as XML 1. |
||
| 3006 | * </td> |
||
| 3007 | * </tr> |
||
| 3008 | * <tr valign="top"> |
||
| 3009 | * <td><b>ENT_XHTML</b></td> |
||
| 3010 | * <td> |
||
| 3011 | * Handle code as XHTML. |
||
| 3012 | * </td> |
||
| 3013 | * </tr> |
||
| 3014 | * <tr valign="top"> |
||
| 3015 | * <td><b>ENT_HTML5</b></td> |
||
| 3016 | * <td> |
||
| 3017 | * Handle code as HTML 5. |
||
| 3018 | * </td> |
||
| 3019 | * </tr> |
||
| 3020 | * </table> |
||
| 3021 | * </p> |
||
| 3022 | * @param string $encoding [optional] <p> |
||
| 3023 | * Like <b>htmlspecialchars</b>, |
||
| 3024 | * <b>htmlentities</b> takes an optional third argument |
||
| 3025 | * <i>encoding</i> which defines encoding used in |
||
| 3026 | * conversion. |
||
| 3027 | * Although this argument is technically optional, you are highly |
||
| 3028 | * encouraged to specify the correct value for your code. |
||
| 3029 | * </p> |
||
| 3030 | * @param bool $double_encode [optional] <p> |
||
| 3031 | * When <i>double_encode</i> is turned off PHP will not |
||
| 3032 | * encode existing html entities. The default is to convert everything. |
||
| 3033 | * </p> |
||
| 3034 | * |
||
| 3035 | * |
||
| 3036 | * @return string the encoded string. |
||
| 3037 | * </p> |
||
| 3038 | * <p> |
||
| 3039 | * If the input <i>string</i> contains an invalid code unit |
||
| 3040 | * sequence within the given <i>encoding</i> an empty string |
||
| 3041 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
| 3042 | * <b>ENT_SUBSTITUTE</b> flags are set. |
||
| 3043 | */ |
||
| 3044 | public static function htmlentities($str, $flags = ENT_COMPAT, $encoding = 'UTF-8', $double_encode = true) |
||
| 3048 | |||
| 3049 | /** |
||
| 3050 | * Convert special characters to HTML entities: UTF-8 version of htmlspecialchars() |
||
| 3051 | * |
||
| 3052 | * @link http://php.net/manual/en/function.htmlspecialchars.php |
||
| 3053 | * |
||
| 3054 | * @param string $str <p> |
||
| 3055 | * The string being converted. |
||
| 3056 | * </p> |
||
| 3057 | * @param int $flags [optional] <p> |
||
| 3058 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
||
| 3059 | * invalid code unit sequences and the used document type. The default is |
||
| 3060 | * ENT_COMPAT | ENT_HTML401. |
||
| 3061 | * <table> |
||
| 3062 | 1 | * Available <i>flags</i> constants |
|
| 3063 | * <tr valign="top"> |
||
| 3064 | 1 | * <td>Constant Name</td> |
|
| 3065 | * <td>Description</td> |
||
| 3066 | * </tr> |
||
| 3067 | * <tr valign="top"> |
||
| 3068 | * <td><b>ENT_COMPAT</b></td> |
||
| 3069 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 3070 | * </tr> |
||
| 3071 | * <tr valign="top"> |
||
| 3072 | 1 | * <td><b>ENT_QUOTES</b></td> |
|
| 3073 | * <td>Will convert both double and single quotes.</td> |
||
| 3074 | 1 | * </tr> |
|
| 3075 | * <tr valign="top"> |
||
| 3076 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 3077 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 3078 | * </tr> |
||
| 3079 | * <tr valign="top"> |
||
| 3080 | * <td><b>ENT_IGNORE</b></td> |
||
| 3081 | * <td> |
||
| 3082 | * Silently discard invalid code unit sequences instead of returning |
||
| 3083 | * an empty string. Using this flag is discouraged as it |
||
| 3084 | * may have security implications. |
||
| 3085 | * </td> |
||
| 3086 | * </tr> |
||
| 3087 | * <tr valign="top"> |
||
| 3088 | * <td><b>ENT_SUBSTITUTE</b></td> |
||
| 3089 | * <td> |
||
| 3090 | * Replace invalid code unit sequences with a Unicode Replacement Character |
||
| 3091 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
| 3092 | * </td> |
||
| 3093 | * </tr> |
||
| 3094 | * <tr valign="top"> |
||
| 3095 | * <td><b>ENT_DISALLOWED</b></td> |
||
| 3096 | * <td> |
||
| 3097 | * Replace invalid code points for the given document type with a |
||
| 3098 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
| 3099 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
| 3100 | * instance, to ensure the well-formedness of XML documents with |
||
| 3101 | * embedded external content. |
||
| 3102 | * </td> |
||
| 3103 | 1 | * </tr> |
|
| 3104 | * <tr valign="top"> |
||
| 3105 | 1 | * <td><b>ENT_HTML401</b></td> |
|
| 3106 | * <td> |
||
| 3107 | * Handle code as HTML 4.01. |
||
| 3108 | * </td> |
||
| 3109 | * </tr> |
||
| 3110 | * <tr valign="top"> |
||
| 3111 | * <td><b>ENT_XML1</b></td> |
||
| 3112 | * <td> |
||
| 3113 | * Handle code as XML 1. |
||
| 3114 | * </td> |
||
| 3115 | 1 | * </tr> |
|
| 3116 | * <tr valign="top"> |
||
| 3117 | 1 | * <td><b>ENT_XHTML</b></td> |
|
| 3118 | * <td> |
||
| 3119 | * Handle code as XHTML. |
||
| 3120 | * </td> |
||
| 3121 | * </tr> |
||
| 3122 | * <tr valign="top"> |
||
| 3123 | * <td><b>ENT_HTML5</b></td> |
||
| 3124 | * <td> |
||
| 3125 | * Handle code as HTML 5. |
||
| 3126 | * </td> |
||
| 3127 | 1 | * </tr> |
|
| 3128 | * </table> |
||
| 3129 | 1 | * </p> |
|
| 3130 | * @param string $encoding [optional] <p> |
||
| 3131 | * Defines encoding used in conversion. |
||
| 3132 | * </p> |
||
| 3133 | * <p> |
||
| 3134 | * For the purposes of this function, the encodings |
||
| 3135 | * ISO-8859-1, ISO-8859-15, |
||
| 3136 | * UTF-8, cp866, |
||
| 3137 | * cp1251, cp1252, and |
||
| 3138 | * KOI8-R are effectively equivalent, provided the |
||
| 3139 | * <i>string</i> itself is valid for the encoding, as |
||
| 3140 | * the characters affected by <b>htmlspecialchars</b> occupy |
||
| 3141 | * the same positions in all of these encodings. |
||
| 3142 | * </p> |
||
| 3143 | * @param bool $double_encode [optional] <p> |
||
| 3144 | * When <i>double_encode</i> is turned off PHP will not |
||
| 3145 | * encode existing html entities, the default is to convert everything. |
||
| 3146 | * </p> |
||
| 3147 | * |
||
| 3148 | * @return string The converted string. |
||
| 3149 | * </p> |
||
| 3150 | * <p> |
||
| 3151 | * If the input <i>string</i> contains an invalid code unit |
||
| 3152 | * sequence within the given <i>encoding</i> an empty string |
||
| 3153 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
| 3154 | * <b>ENT_SUBSTITUTE</b> flags are set. |
||
| 3155 | */ |
||
| 3156 | public static function htmlspecialchars($str, $flags = ENT_COMPAT, $encoding = 'UTF-8', $double_encode = true) |
||
| 3160 | |||
| 3161 | /** |
||
| 3162 | * checks whether iconv is available on the server |
||
| 3163 | * |
||
| 3164 | * @return bool True if available, False otherwise |
||
| 3165 | */ |
||
| 3166 | public static function iconv_loaded() |
||
| 3170 | |||
| 3171 | /** |
||
| 3172 | * Converts Integer to hexadecimal U+xxxx code point representation. |
||
| 3173 | * |
||
| 3174 | * @param int $int The integer to be converted to hexadecimal code point. |
||
| 3175 | * @param string $pfix |
||
| 3176 | * |
||
| 3177 | * @return string The code point, or empty string on failure. |
||
| 3178 | */ |
||
| 3179 | 16 | public static function int_to_hex($int, $pfix = 'U+') |
|
| 3191 | |||
| 3192 | 4 | /** |
|
| 3193 | * checks whether intl is available on the server |
||
| 3194 | 4 | * |
|
| 3195 | * @return bool True if available, False otherwise |
||
| 3196 | */ |
||
| 3197 | public static function intl_loaded() |
||
| 3201 | |||
| 3202 | /** |
||
| 3203 | * checks whether intl-char is available on the server |
||
| 3204 | 1 | * |
|
| 3205 | * @return bool True if available, False otherwise |
||
| 3206 | 1 | */ |
|
| 3207 | public static function intlChar_loaded() |
||
| 3211 | |||
| 3212 | 1 | /** |
|
| 3213 | 1 | * alias for "UTF8::is_ascii()" |
|
| 3214 | * |
||
| 3215 | 1 | * @param string $str |
|
| 3216 | * |
||
| 3217 | * @return boolean |
||
| 3218 | */ |
||
| 3219 | public static function isAscii($str) |
||
| 3223 | |||
| 3224 | /** |
||
| 3225 | * alias for "UTF8::is_base64" |
||
| 3226 | 4 | * |
|
| 3227 | * @param string $str |
||
| 3228 | * |
||
| 3229 | 4 | * @return bool |
|
| 3230 | */ |
||
| 3231 | public static function isBase64($str) |
||
| 3235 | 4 | ||
| 3236 | 4 | /** |
|
| 3237 | 4 | * alias for "UTF8::is_bom" |
|
| 3238 | 3 | * |
|
| 3239 | * @param string $utf8_chr |
||
| 3240 | 4 | * |
|
| 3241 | * @return boolean |
||
| 3242 | */ |
||
| 3243 | public static function isBom($utf8_chr) |
||
| 3247 | |||
| 3248 | /** |
||
| 3249 | * Try to check if a string is a json-string... |
||
| 3250 | * |
||
| 3251 | * @param $str |
||
| 3252 | * |
||
| 3253 | * @return bool |
||
| 3254 | */ |
||
| 3255 | public static function isJson($str) |
||
| 3273 | 2 | ||
| 3274 | /** |
||
| 3275 | 2 | * check if string contains any html-tags <lall> |
|
| 3276 | * |
||
| 3277 | * @param string $str |
||
| 3278 | * |
||
| 3279 | * @return boolean |
||
| 3280 | */ |
||
| 3281 | public static function isHtml($str) |
||
| 3300 | 1 | ||
| 3301 | 2 | /** |
|
| 3302 | 2 | * alias for "UTF8::is_utf8" |
|
| 3303 | 2 | * |
|
| 3304 | * @param string $str |
||
| 3305 | 2 | * |
|
| 3306 | 2 | * @return bool |
|
| 3307 | 2 | */ |
|
| 3308 | 2 | public static function isUtf8($str) |
|
| 3312 | 2 | ||
| 3313 | 2 | /** |
|
| 3314 | 1 | * Checks if a string is 7 bit ASCII. |
|
| 3315 | 1 | * |
|
| 3316 | 2 | * @param string $str The string to check. |
|
| 3317 | 2 | * |
|
| 3318 | 2 | * @return bool <strong>true</strong> if it is ASCII<br /> |
|
| 3319 | * <strong>false</strong> otherwise |
||
| 3320 | 2 | */ |
|
| 3321 | 1 | public static function is_ascii($str) |
|
| 3325 | |||
| 3326 | /** |
||
| 3327 | * Returns true if the string is base64 encoded, false otherwise. |
||
| 3328 | 2 | * |
|
| 3329 | * @param string $str |
||
| 3330 | 2 | * |
|
| 3331 | * @return bool Whether or not $str is base64 encoded |
||
| 3332 | */ |
||
| 3333 | public static function is_base64($str) |
||
| 3347 | 2 | ||
| 3348 | 2 | /** |
|
| 3349 | 2 | * Check if the input is binary... (is look like a hack) |
|
| 3350 | 2 | * |
|
| 3351 | 2 | * @param string $input |
|
| 3352 | 2 | * |
|
| 3353 | 2 | * @return bool |
|
| 3354 | */ |
||
| 3355 | public static function is_binary($input) |
||
| 3372 | 1 | ||
| 3373 | 1 | /** |
|
| 3374 | * Check if the file is binary. |
||
| 3375 | 2 | * |
|
| 3376 | * @param string $file |
||
| 3377 | * |
||
| 3378 | * @return boolean |
||
| 3379 | */ |
||
| 3380 | public static function is_binary_file($file) |
||
| 3392 | |||
| 3393 | /** |
||
| 3394 | * Checks if the given string is exactly "UTF8 - Byte Order Mark". |
||
| 3395 | * |
||
| 3396 | * WARNING: Use "UTF8::string_has_bom()" if you will check BOM in a string. |
||
| 3397 | 34 | * |
|
| 3398 | * @param string $utf8_chr The input string. |
||
| 3399 | 34 | * |
|
| 3400 | * @return bool True if the $utf8_chr is Byte Order Mark, False otherwise. |
||
| 3401 | 34 | */ |
|
| 3402 | 3 | public static function is_bom($utf8_chr) |
|
| 3406 | |||
| 3407 | /** |
||
| 3408 | * Check if the string is UTF-16. |
||
| 3409 | * |
||
| 3410 | * @param string $str |
||
| 3411 | * |
||
| 3412 | * @return int|false false if is't not UTF16, 1 for UTF-16LE, 2 for UTF-16BE. |
||
| 3413 | */ |
||
| 3414 | View Code Duplication | public static function is_utf16($str) |
|
| 3461 | 7 | ||
| 3462 | /** |
||
| 3463 | 3 | * Check if the string is UTF-32. |
|
| 3464 | 3 | * |
|
| 3465 | 3 | * @param string $str |
|
| 3466 | 3 | * |
|
| 3467 | 3 | * @return int|false false if is't not UTF16, 1 for UTF-32LE, 2 for UTF-32BE. |
|
| 3468 | */ |
||
| 3469 | View Code Duplication | public static function is_utf32($str) |
|
| 3516 | 32 | ||
| 3517 | /** |
||
| 3518 | 14 | * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters. |
|
| 3519 | * |
||
| 3520 | * @see http://hsivonen.iki.fi/php-utf8/ |
||
| 3521 | * |
||
| 3522 | * @param string $str The string to be checked. |
||
| 3523 | * |
||
| 3524 | * @return bool |
||
| 3525 | */ |
||
| 3526 | public static function is_utf8($str) |
||
| 3650 | 23 | ||
| 3651 | /** |
||
| 3652 | 23 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
|
| 3653 | * Decodes a JSON string |
||
| 3654 | * |
||
| 3655 | * @link http://php.net/manual/en/function.json-decode.php |
||
| 3656 | * |
||
| 3657 | * @param string $json <p> |
||
| 3658 | * The <i>json</i> string being decoded. |
||
| 3659 | * </p> |
||
| 3660 | * <p> |
||
| 3661 | * This function only works with UTF-8 encoded strings. |
||
| 3662 | 1 | * </p> |
|
| 3663 | * <p>PHP implements a superset of |
||
| 3664 | 1 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
|
| 3665 | * only supports these values when they are nested inside an array or an object. |
||
| 3666 | * </p> |
||
| 3667 | * @param bool $assoc [optional] <p> |
||
| 3668 | 1 | * When <b>TRUE</b>, returned objects will be converted into |
|
| 3669 | * associative arrays. |
||
| 3670 | * </p> |
||
| 3671 | * @param int $depth [optional] <p> |
||
| 3672 | * User specified recursion depth. |
||
| 3673 | * </p> |
||
| 3674 | * @param int $options [optional] <p> |
||
| 3675 | * Bitmask of JSON decode options. Currently only |
||
| 3676 | * <b>JSON_BIGINT_AS_STRING</b> |
||
| 3677 | * is supported (default is to cast large integers as floats) |
||
| 3678 | * </p> |
||
| 3679 | 1 | * |
|
| 3680 | * @return mixed the value encoded in <i>json</i> in appropriate |
||
| 3681 | 1 | * PHP type. Values true, false and |
|
| 3682 | 1 | * null (case-insensitive) are returned as <b>TRUE</b>, <b>FALSE</b> |
|
| 3683 | 1 | * and <b>NULL</b> respectively. <b>NULL</b> is returned if the |
|
| 3684 | * <i>json</i> cannot be decoded or if the encoded |
||
| 3685 | 1 | * data is deeper than the recursion limit. |
|
| 3686 | */ |
||
| 3687 | public static function json_decode($json, $assoc = false, $depth = 512, $options = 0) |
||
| 3699 | 2 | ||
| 3700 | 2 | /** |
|
| 3701 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
||
| 3702 | 2 | * Returns the JSON representation of a value |
|
| 3703 | * |
||
| 3704 | * @link http://php.net/manual/en/function.json-encode.php |
||
| 3705 | * |
||
| 3706 | * @param mixed $value <p> |
||
| 3707 | * The <i>value</i> being encoded. Can be any type except |
||
| 3708 | * a resource. |
||
| 3709 | * </p> |
||
| 3710 | * <p> |
||
| 3711 | * All string data must be UTF-8 encoded. |
||
| 3712 | 1 | * </p> |
|
| 3713 | * <p>PHP implements a superset of |
||
| 3714 | 1 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
|
| 3715 | * only supports these values when they are nested inside an array or an object. |
||
| 3716 | * </p> |
||
| 3717 | * @param int $options [optional] <p> |
||
| 3718 | 1 | * Bitmask consisting of <b>JSON_HEX_QUOT</b>, |
|
| 3719 | * <b>JSON_HEX_TAG</b>, |
||
| 3720 | * <b>JSON_HEX_AMP</b>, |
||
| 3721 | * <b>JSON_HEX_APOS</b>, |
||
| 3722 | * <b>JSON_NUMERIC_CHECK</b>, |
||
| 3723 | * <b>JSON_PRETTY_PRINT</b>, |
||
| 3724 | * <b>JSON_UNESCAPED_SLASHES</b>, |
||
| 3725 | * <b>JSON_FORCE_OBJECT</b>, |
||
| 3726 | * <b>JSON_UNESCAPED_UNICODE</b>. The behaviour of these |
||
| 3727 | * constants is described on |
||
| 3728 | 13 | * the JSON constants page. |
|
| 3729 | * </p> |
||
| 3730 | 13 | * @param int $depth [optional] <p> |
|
| 3731 | * Set the maximum depth. Must be greater than zero. |
||
| 3732 | 13 | * </p> |
|
| 3733 | * |
||
| 3734 | * @return string a JSON encoded string on success or <b>FALSE</b> on failure. |
||
| 3735 | 13 | */ |
|
| 3736 | 13 | public static function json_encode($value, $options = 0, $depth = 512) |
|
| 3748 | 13 | ||
| 3749 | /** |
||
| 3750 | 13 | * Makes string's first char lowercase. |
|
| 3751 | 2 | * |
|
| 3752 | * @param string $str The input string |
||
| 3753 | * |
||
| 3754 | 13 | * @return string The resulting string |
|
| 3755 | */ |
||
| 3756 | public static function lcfirst($str) |
||
| 3760 | |||
| 3761 | /** |
||
| 3762 | * Strip whitespace or other characters from beginning of a UTF-8 string. |
||
| 3763 | * |
||
| 3764 | 2 | * WARNING: This is much slower then "ltrim()" !!!! |
|
| 3765 | * |
||
| 3766 | 2 | * @param string $str The string to be trimmed |
|
| 3767 | 2 | * @param string $chars Optional characters to be stripped |
|
| 3768 | * |
||
| 3769 | 2 | * @return string The string with unwanted characters stripped from the left |
|
| 3770 | 1 | */ |
|
| 3771 | 1 | View Code Duplication | public static function ltrim($str = '', $chars = INF) |
| 3783 | |||
| 3784 | /** |
||
| 3785 | * Returns the UTF-8 character with the maximum code point in the given data. |
||
| 3786 | 8 | * |
|
| 3787 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
||
| 3788 | 8 | * |
|
| 3789 | 8 | * @return string The character with the highest code point than others. |
|
| 3790 | */ |
||
| 3791 | 8 | View Code Duplication | public static function max($arg) |
| 3799 | 1 | ||
| 3800 | 1 | /** |
|
| 3801 | * Calculates and returns the maximum number of bytes taken by any |
||
| 3802 | 2 | * UTF-8 encoded character in the given string. |
|
| 3803 | 2 | * |
|
| 3804 | * @param string $str The original Unicode string. |
||
| 3805 | 8 | * |
|
| 3806 | 8 | * @return int An array of byte lengths of each character. |
|
| 3807 | 1 | */ |
|
| 3808 | 1 | public static function max_chr_width($str) |
|
| 3817 | |||
| 3818 | /** |
||
| 3819 | * checks whether mbstring is available on the server |
||
| 3820 | * |
||
| 3821 | * @return bool True if available, False otherwise |
||
| 3822 | */ |
||
| 3823 | public static function mbstring_loaded() |
||
| 3833 | |||
| 3834 | /** |
||
| 3835 | * Returns the UTF-8 character with the minimum code point in the given data. |
||
| 3836 | * |
||
| 3837 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
||
| 3838 | * |
||
| 3839 | * @return string The character with the lowest code point than others. |
||
| 3840 | */ |
||
| 3841 | View Code Duplication | public static function min($arg) |
|
| 3849 | |||
| 3850 | /** |
||
| 3851 | * Normalize the encoding-name input. |
||
| 3852 | * |
||
| 3853 | * @param string $encoding e.g.: ISO, UTF8, WINDOWS-1251 etc. |
||
| 3854 | * |
||
| 3855 | 15 | * @return string e.g.: ISO-8859-1, UTF-8, WINDOWS-1251 etc. |
|
| 3856 | */ |
||
| 3857 | 15 | public static function normalizeEncoding($encoding) |
|
| 3902 | 1 | ||
| 3903 | /** |
||
| 3904 | 1 | * Normalize MS Word special characters. |
|
| 3905 | 1 | * |
|
| 3906 | * @param string $str The string to be normalized. |
||
| 3907 | * |
||
| 3908 | * @return string |
||
| 3909 | */ |
||
| 3910 | public static function normalize_msword($str) |
||
| 3922 | |||
| 3923 | /** |
||
| 3924 | * Normalize the whitespace. |
||
| 3925 | * |
||
| 3926 | 1 | * @param string $str The string to be normalized. |
|
| 3927 | * @param bool $keepNonBreakingSpace Set to true, to keep non-breaking-spaces. |
||
| 3928 | 1 | * @param bool $keepBidiUnicodeControls Set to true, to keep non-printable (for the web) bidirectional text chars. |
|
| 3929 | 1 | * |
|
| 3930 | * @return string |
||
| 3931 | */ |
||
| 3932 | 1 | public static function normalize_whitespace($str, $keepNonBreakingSpace = false, $keepBidiUnicodeControls = false) |
|
| 3961 | 1 | ||
| 3962 | 1 | /** |
|
| 3963 | * Format a number with grouped thousands. |
||
| 3964 | * |
||
| 3965 | * @param float $number |
||
| 3966 | * @param int $decimals |
||
| 3967 | * @param string $dec_point |
||
| 3968 | * @param string $thousands_sep |
||
| 3969 | * |
||
| 3970 | * @return string |
||
| 3971 | */ |
||
| 3972 | public static function number_format($number, $decimals = 0, $dec_point = '.', $thousands_sep = ',') |
||
| 3997 | 3 | ||
| 3998 | /** |
||
| 3999 | 7 | * Calculates Unicode code point of the given UTF-8 encoded character. |
|
| 4000 | * |
||
| 4001 | * @param string $s The character of which to calculate code point. |
||
| 4002 | 3 | * |
|
| 4003 | 1 | * @return int Unicode code point of the given character,<br /> |
|
| 4004 | 1 | * 0 on invalid UTF-8 byte sequence. |
|
| 4005 | */ |
||
| 4006 | public static function ord($s) |
||
| 4039 | |||
| 4040 | /** |
||
| 4041 | * Parses the string into variables. |
||
| 4042 | * |
||
| 4043 | * WARNING: This differs from parse_str() by returning the results |
||
| 4044 | * instead of placing them in the local scope! |
||
| 4045 | * |
||
| 4046 | * @link http://php.net/manual/en/function.parse-str.php |
||
| 4047 | * |
||
| 4048 | * @param string $str <p> |
||
| 4049 | * The input string. |
||
| 4050 | * </p> |
||
| 4051 | * @param array $result <p> |
||
| 4052 | 36 | * If the second parameter arr is present, |
|
| 4053 | * variables are stored in this variable as array elements instead. |
||
| 4054 | * </p> |
||
| 4055 | 36 | * |
|
| 4056 | * @return void |
||
| 4057 | */ |
||
| 4058 | public static function parse_str($str, &$result) |
||
| 4067 | 36 | ||
| 4068 | 36 | /** |
|
| 4069 | * checks if \u modifier is available that enables Unicode support in PCRE. |
||
| 4070 | 36 | * |
|
| 4071 | * @return bool True if support is available, false otherwise |
||
| 4072 | */ |
||
| 4073 | public static function pcre_utf8_support() |
||
| 4078 | |||
| 4079 | /** |
||
| 4080 | * Create an array containing a range of UTF-8 characters. |
||
| 4081 | 36 | * |
|
| 4082 | * @param mixed $var1 Numeric or hexadecimal code points, or a UTF-8 character to start from. |
||
| 4083 | 36 | * @param mixed $var2 Numeric or hexadecimal code points, or a UTF-8 character to end at. |
|
| 4084 | * |
||
| 4085 | 36 | * @return array |
|
| 4086 | 36 | */ |
|
| 4087 | 36 | public static function range($var1, $var2) |
|
| 4125 | |||
| 4126 | /** |
||
| 4127 | 40 | * Remove the BOM from UTF-8 / UTF-16 / UTF-32 strings. |
|
| 4128 | * |
||
| 4129 | 40 | * @param string $str |
|
| 4130 | * |
||
| 4131 | 40 | * @return string |
|
| 4132 | */ |
||
| 4133 | 40 | public static function removeBOM($str = '') |
|
| 4157 | |||
| 4158 | /** |
||
| 4159 | 16 | * Removes duplicate occurrences of a string in another string. |
|
| 4160 | * |
||
| 4161 | 16 | * @param string $str The base string |
|
| 4162 | * @param string|array $what String to search for in the base string |
||
| 4163 | * |
||
| 4164 | * @return string The result string with removed duplicates |
||
| 4165 | */ |
||
| 4166 | public static function remove_duplicates($str, $what = ' ') |
||
| 4180 | |||
| 4181 | 2 | /** |
|
| 4182 | * Remove Invisible Characters |
||
| 4183 | 2 | * |
|
| 4184 | 1 | * This prevents sandwiching null characters |
|
| 4185 | * between ascii characters, like Java\0script. |
||
| 4186 | * |
||
| 4187 | 2 | * copy&past from https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Common.php |
|
| 4188 | * |
||
| 4189 | * @param string $str |
||
| 4190 | * @param bool $url_encoded |
||
| 4191 | * @param string $replacement |
||
| 4192 | * |
||
| 4193 | * @return string |
||
| 4194 | */ |
||
| 4195 | public static function remove_invisible_characters($str, $url_encoded = true, $replacement = '') |
||
| 4215 | |||
| 4216 | /** |
||
| 4217 | * replace diamond question mark (�) |
||
| 4218 | 24 | * |
|
| 4219 | 24 | * @param string $str |
|
| 4220 | 24 | * @param string $unknown |
|
| 4221 | 24 | * |
|
| 4222 | 24 | * @return string |
|
| 4223 | */ |
||
| 4224 | 24 | public static function replace_diamond_question_mark($str, $unknown = '?') |
|
| 4238 | |||
| 4239 | /** |
||
| 4240 | * Strip whitespace or other characters from end of a UTF-8 string. |
||
| 4241 | * |
||
| 4242 | * WARNING: This is much slower then "rtrim()" !!!! |
||
| 4243 | * |
||
| 4244 | * @param string $str The string to be trimmed |
||
| 4245 | * @param string $chars Optional characters to be stripped |
||
| 4246 | * |
||
| 4247 | * @return string The string with unwanted characters stripped from the right |
||
| 4248 | */ |
||
| 4249 | View Code Duplication | public static function rtrim($str = '', $chars = INF) |
|
| 4261 | |||
| 4262 | 24 | /** |
|
| 4263 | * rxClass |
||
| 4264 | * |
||
| 4265 | * @param string $s |
||
| 4266 | 24 | * @param string $class |
|
| 4267 | * |
||
| 4268 | * @return string |
||
| 4269 | */ |
||
| 4270 | protected static function rxClass($s, $class = '') |
||
| 4307 | |||
| 4308 | /** |
||
| 4309 | * Echo native UTF8-Support libs, e.g. for debugging. |
||
| 4310 | 3 | */ |
|
| 4311 | 3 | public static function showSupport() |
|
| 4317 | 3 | ||
| 4318 | /** |
||
| 4319 | * Converts a UTF-8 character to HTML Numbered Entity like "{". |
||
| 4320 | 3 | * |
|
| 4321 | 3 | * @param string $chr The Unicode character to be encoded as numbered entity. |
|
| 4322 | 3 | * @param bool $keepAsciiChars Keep ASCII chars. |
|
| 4323 | 3 | * |
|
| 4324 | * @return string The HTML numbered entity. |
||
| 4325 | */ |
||
| 4326 | public static function single_chr_html_encode($chr, $keepAsciiChars = false) |
||
| 4340 | |||
| 4341 | /** |
||
| 4342 | * Convert a string to an array of Unicode characters. |
||
| 4343 | * |
||
| 4344 | * @param string $str The string to split into array. |
||
| 4345 | * @param int $length Max character length of each array element. |
||
| 4346 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string. |
||
| 4347 | * |
||
| 4348 | * @return array An array containing chunks of the string. |
||
| 4349 | */ |
||
| 4350 | public static function split($str, $length = 1, $cleanUtf8 = false) |
||
| 4419 | |||
| 4420 | /** |
||
| 4421 | 2 | * Optimized "\mb_detect_encoding()"-function -> with support for UTF-16 and UTF-32. |
|
| 4422 | * |
||
| 4423 | 2 | * @param string $str |
|
| 4424 | * |
||
| 4425 | 2 | * @return false|string The detected string-encoding e.g. UTF-8 or UTF-16BE,<br /> |
|
| 4426 | 2 | * otherwise it will return false. |
|
| 4427 | */ |
||
| 4428 | 2 | public static function str_detect_encoding($str) |
|
| 4497 | |||
| 4498 | /** |
||
| 4499 | * Case-insensitive and UTF-8 safe version of <function>str_replace</function>. |
||
| 4500 | * |
||
| 4501 | * @link http://php.net/manual/en/function.str-ireplace.php |
||
| 4502 | * |
||
| 4503 | * @param mixed $search <p> |
||
| 4504 | * Every replacement with search array is |
||
| 4505 | * performed on the result of previous replacement. |
||
| 4506 | * </p> |
||
| 4507 | * @param mixed $replace <p> |
||
| 4508 | * </p> |
||
| 4509 | * @param mixed $subject <p> |
||
| 4510 | * If subject is an array, then the search and |
||
| 4511 | * replace is performed with every entry of |
||
| 4512 | 12 | * subject, and the return value is an array as |
|
| 4513 | * well. |
||
| 4514 | 12 | * </p> |
|
| 4515 | * @param int $count [optional] <p> |
||
| 4516 | * The number of matched and replaced needles will |
||
| 4517 | * be returned in count which is passed by |
||
| 4518 | * reference. |
||
| 4519 | * </p> |
||
| 4520 | * |
||
| 4521 | * @return mixed a string or an array of replacements. |
||
| 4522 | * @since 5.0 |
||
| 4523 | */ |
||
| 4524 | public static function str_ireplace($search, $replace, $subject, &$count = null) |
||
| 4542 | 1 | ||
| 4543 | /** |
||
| 4544 | 1 | * Limit the number of characters in a string, but also after the next word. |
|
| 4545 | * |
||
| 4546 | 1 | * @param string $str |
|
| 4547 | 1 | * @param int $length |
|
| 4548 | 1 | * @param string $strAddOn |
|
| 4549 | * |
||
| 4550 | 1 | * @return string |
|
| 4551 | 1 | */ |
|
| 4552 | 1 | public static function str_limit_after_word($str, $length = 100, $strAddOn = '...') |
|
| 4583 | 16 | ||
| 4584 | 16 | /** |
|
| 4585 | 17 | * Pad a UTF-8 string to given length with another string. |
|
| 4586 | * |
||
| 4587 | * @param string $input The input string |
||
| 4588 | * @param int $pad_length The length of return string |
||
| 4589 | * @param string $pad_string String to use for padding the input string |
||
| 4590 | 17 | * @param int $pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT or STR_PAD_BOTH |
|
| 4591 | 17 | * |
|
| 4592 | * @return string Returns the padded string |
||
| 4593 | */ |
||
| 4594 | 1 | public static function str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) |
|
| 4629 | 1 | ||
| 4630 | 1 | /** |
|
| 4631 | 1 | * Repeat a string. |
|
| 4632 | * |
||
| 4633 | 1 | * @param string $input <p> |
|
| 4634 | * The string to be repeated. |
||
| 4635 | * </p> |
||
| 4636 | * @param int $multiplier <p> |
||
| 4637 | * Number of time the input string should be |
||
| 4638 | * repeated. |
||
| 4639 | * </p> |
||
| 4640 | * <p> |
||
| 4641 | * multiplier has to be greater than or equal to 0. |
||
| 4642 | * If the multiplier is set to 0, the function |
||
| 4643 | * will return an empty string. |
||
| 4644 | * </p> |
||
| 4645 | * |
||
| 4646 | * @return string the repeated string. |
||
| 4647 | */ |
||
| 4648 | public static function str_repeat($input, $multiplier) |
||
| 4654 | 8 | ||
| 4655 | /** |
||
| 4656 | 8 | * INFO: this is only a wrapper for "str_replace()" -> the original functions is already UTF-8 safe |
|
| 4657 | * |
||
| 4658 | 8 | * (PHP 4, PHP 5)<br/> |
|
| 4659 | * Replace all occurrences of the search string with the replacement string |
||
| 4660 | 8 | * |
|
| 4661 | 2 | * @link http://php.net/manual/en/function.str-replace.php |
|
| 4662 | * |
||
| 4663 | * @param mixed $search <p> |
||
| 4664 | 7 | * The value being searched for, otherwise known as the needle. |
|
| 4665 | * An array may be used to designate multiple needles. |
||
| 4666 | 7 | * </p> |
|
| 4667 | 7 | * @param mixed $replace <p> |
|
| 4668 | 7 | * The replacement value that replaces found search |
|
| 4669 | * values. An array may be used to designate multiple replacements. |
||
| 4670 | 7 | * </p> |
|
| 4671 | * @param mixed $subject <p> |
||
| 4672 | 7 | * The string or array being searched and replaced on, |
|
| 4673 | 6 | * otherwise known as the haystack. |
|
| 4674 | * </p> |
||
| 4675 | * <p> |
||
| 4676 | 4 | * If subject is an array, then the search and |
|
| 4677 | * replace is performed with every entry of |
||
| 4678 | * subject, and the return value is an array as |
||
| 4679 | 4 | * well. |
|
| 4680 | 4 | * </p> |
|
| 4681 | 4 | * @param int $count [optional] If passed, this will hold the number of matched and replaced needles. |
|
| 4682 | * |
||
| 4683 | 4 | * @return mixed This function returns a string or an array with the replaced values. |
|
| 4684 | 3 | */ |
|
| 4685 | public static function str_replace($search, $replace, $subject, &$count = null) |
||
| 4689 | |||
| 4690 | 3 | /** |
|
| 4691 | 1 | * Shuffles all the characters in the string. |
|
| 4692 | * |
||
| 4693 | 1 | * @param string $str The input string |
|
| 4694 | 1 | * |
|
| 4695 | 1 | * @return string The shuffled string. |
|
| 4696 | */ |
||
| 4697 | 1 | public static function str_shuffle($str) |
|
| 4705 | |||
| 4706 | /** |
||
| 4707 | * Sort all characters according to code points. |
||
| 4708 | * |
||
| 4709 | * @param string $str A UTF-8 string. |
||
| 4710 | * @param bool $unique Sort unique. If true, repeated characters are ignored. |
||
| 4711 | * @param bool $desc If true, will sort characters in reverse code point order. |
||
| 4712 | 1 | * |
|
| 4713 | 3 | * @return string String of sorted characters |
|
| 4714 | */ |
||
| 4715 | 4 | public static function str_sort($str, $unique = false, $desc = false) |
|
| 4731 | 2 | ||
| 4732 | 1 | /** |
|
| 4733 | * Convert a string to an array. |
||
| 4734 | 2 | * |
|
| 4735 | * @param string $str |
||
| 4736 | 4 | * @param int $len |
|
| 4737 | 4 | * |
|
| 4738 | 4 | * @return array |
|
| 4739 | 4 | */ |
|
| 4740 | 1 | public static function str_split($str, $len = 1) |
|
| 4780 | |||
| 4781 | /** |
||
| 4782 | * Get a binary representation of a specific character. |
||
| 4783 | * |
||
| 4784 | * @param string $str The input character. |
||
| 4785 | * |
||
| 4786 | * @return string |
||
| 4787 | */ |
||
| 4788 | public static function str_to_binary($str) |
||
| 4807 | 8 | ||
| 4808 | 5 | /** |
|
| 4809 | 5 | * US-ASCII transliterations of Unicode text. |
|
| 4810 | 8 | * |
|
| 4811 | * Ported Sean M. Burke's Text::Unidecode Perl module (He did all the hard work!) |
||
| 4812 | * Warning: you should only pass this well formed UTF-8! |
||
| 4813 | * Be aware it works by making a copy of the input string which it appends transliterated |
||
| 4814 | * characters to - it uses a PHP output buffer to do this - it means, memory use will increase, |
||
| 4815 | * requiring up to the same amount again as the input string |
||
| 4816 | * |
||
| 4817 | * @see http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm |
||
| 4818 | * |
||
| 4819 | * @author <[email protected]> |
||
| 4820 | * |
||
| 4821 | * @param string $str UTF-8 string to convert |
||
| 4822 | * @param string $unknown Character use if character unknown. (default is ?) |
||
| 4823 | 5 | * |
|
| 4824 | * @return string US-ASCII string |
||
| 4825 | 5 | */ |
|
| 4826 | public static function str_transliterate($str, $unknown = '?') |
||
| 4918 | |||
| 4919 | /** |
||
| 4920 | * Counts number of words in the UTF-8 string. |
||
| 4921 | * |
||
| 4922 | * @param string $str The input string. |
||
| 4923 | * @param int $format <strong>0</strong> => return a number of words<br /> |
||
| 4924 | * <strong>1</strong> => return an array of words |
||
| 4925 | 8 | * <strong>2</strong> => return an array of words with word-offset as key |
|
| 4926 | * @param string $charlist |
||
| 4927 | 8 | * |
|
| 4928 | 8 | * @return array|float The number of words in the string |
|
| 4929 | */ |
||
| 4930 | 8 | public static function str_word_count($str, $format = 0, $charlist = '') |
|
| 4963 | |||
| 4964 | /** |
||
| 4965 | * Case-insensitive string comparison. |
||
| 4966 | 5 | * |
|
| 4967 | * @param string $str1 |
||
| 4968 | 5 | * @param string $str2 |
|
| 4969 | * |
||
| 4970 | * @return int Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. |
||
| 4971 | */ |
||
| 4972 | public static function strcasecmp($str1, $str2) |
||
| 4976 | |||
| 4977 | /** |
||
| 4978 | * String comparison. |
||
| 4979 | * |
||
| 4980 | * @param string $str1 |
||
| 4981 | * @param string $str2 |
||
| 4982 | * |
||
| 4983 | * @return int <strong>< 0</strong> if str1 is less than str2<br /> |
||
| 4984 | * <strong>> 0</strong> if str1 is greater than str2<br /> |
||
| 4985 | 66 | * <strong>0</strong> if they are equal. |
|
| 4986 | */ |
||
| 4987 | 66 | public static function strcmp($str1, $str2) |
|
| 4994 | 65 | ||
| 4995 | /** |
||
| 4996 | * Find length of initial segment not matching mask. |
||
| 4997 | 65 | * |
|
| 4998 | * @param string $str |
||
| 4999 | * @param string $charList |
||
| 5000 | * @param int $offset |
||
| 5001 | 65 | * @param int $length |
|
| 5002 | * |
||
| 5003 | * @return int|null |
||
| 5004 | */ |
||
| 5005 | 65 | public static function strcspn($str, $charList, $offset = 0, $length = 2147483647) |
|
| 5024 | |||
| 5025 | /** |
||
| 5026 | * Makes a UTF-8 string from code points. |
||
| 5027 | * |
||
| 5028 | * @param array $array Integer or Hexadecimal codepoints |
||
| 5029 | * |
||
| 5030 | * @return string UTF-8 encoded string |
||
| 5031 | 2 | */ |
|
| 5032 | public static function string($array) |
||
| 5044 | |||
| 5045 | /** |
||
| 5046 | * Checks if string starts with "UTF-8 BOM" character. |
||
| 5047 | * |
||
| 5048 | * @param string $str The input string. |
||
| 5049 | * |
||
| 5050 | * @return bool True if the string has BOM at the start, False otherwise. |
||
| 5051 | */ |
||
| 5052 | public static function string_has_bom($str) |
||
| 5056 | |||
| 5057 | /** |
||
| 5058 | * Strip HTML and PHP tags from a string. |
||
| 5059 | * |
||
| 5060 | * @link http://php.net/manual/en/function.strip-tags.php |
||
| 5061 | * |
||
| 5062 | * @param string $str <p> |
||
| 5063 | * The input string. |
||
| 5064 | * </p> |
||
| 5065 | * @param string $allowable_tags [optional] <p> |
||
| 5066 | * You can use the optional second parameter to specify tags which should |
||
| 5067 | * not be stripped. |
||
| 5068 | * </p> |
||
| 5069 | * <p> |
||
| 5070 | * HTML comments and PHP tags are also stripped. This is hardcoded and |
||
| 5071 | * can not be changed with allowable_tags. |
||
| 5072 | * </p> |
||
| 5073 | * |
||
| 5074 | * @return string the stripped string. |
||
| 5075 | */ |
||
| 5076 | public static function strip_tags($str, $allowable_tags = null) |
||
| 5083 | |||
| 5084 | /** |
||
| 5085 | * Finds position of first occurrence of a string within another, case insensitive. |
||
| 5086 | * |
||
| 5087 | * @link http://php.net/manual/en/function.mb-stripos.php |
||
| 5088 | * |
||
| 5089 | * @param string $haystack <p> |
||
| 5090 | * The string from which to get the position of the first occurrence |
||
| 5091 | * of needle |
||
| 5092 | * </p> |
||
| 5093 | * @param string $needle <p> |
||
| 5094 | * The string to find in haystack |
||
| 5095 | * </p> |
||
| 5096 | * @param int $offset [optional] <p> |
||
| 5097 | * The position in haystack |
||
| 5098 | * to start searching |
||
| 5099 | * </p> |
||
| 5100 | * @param string $encoding |
||
| 5101 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 5102 | * |
||
| 5103 | 11 | * @return int Return the numeric position of the first occurrence of |
|
| 5104 | * needle in the haystack |
||
| 5105 | 11 | * string, or false if needle is not found. |
|
| 5106 | 11 | */ |
|
| 5107 | public static function stripos($haystack, $needle, $offset = null, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 5131 | |||
| 5132 | /** |
||
| 5133 | 10 | * Returns all of haystack starting from and including the first occurrence of needle to the end. |
|
| 5134 | 1 | * |
|
| 5135 | 1 | * @param string $str |
|
| 5136 | * @param string $needle |
||
| 5137 | 10 | * @param bool $before_needle |
|
| 5138 | * |
||
| 5139 | * @return false|string |
||
| 5140 | */ |
||
| 5141 | public static function stristr($str, $needle, $before_needle = false) |
||
| 5152 | |||
| 5153 | /** |
||
| 5154 | * Get the string length, not the byte-length! |
||
| 5155 | * |
||
| 5156 | * @link http://php.net/manual/en/function.mb-strlen.php |
||
| 5157 | * |
||
| 5158 | * @param string $str The string being checked for length. |
||
| 5159 | * @param string $encoding Set the charset for e.g. "\mb_" function |
||
| 5160 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 5161 | * |
||
| 5162 | * @return int the number of characters in |
||
| 5163 | * string str having character encoding |
||
| 5164 | * encoding. A multi-byte character is |
||
| 5165 | * counted as 1. |
||
| 5166 | */ |
||
| 5167 | public static function strlen($str, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 5196 | |||
| 5197 | /** |
||
| 5198 | * Case insensitive string comparisons using a "natural order" algorithm. |
||
| 5199 | * |
||
| 5200 | 4 | * @param string $str1 |
|
| 5201 | * @param string $str2 |
||
| 5202 | 4 | * |
|
| 5203 | * @return int <strong>< 0</strong> if str1 is less than str2<br /> |
||
| 5204 | * <strong>> 0</strong> if str1 is greater than str2<br /> |
||
| 5205 | * <strong>0</strong> if they are equal |
||
| 5206 | */ |
||
| 5207 | public static function strnatcasecmp($str1, $str2) |
||
| 5211 | |||
| 5212 | /** |
||
| 5213 | * String comparisons using a "natural order" algorithm |
||
| 5214 | * |
||
| 5215 | * @link http://php.net/manual/en/function.strnatcmp.php |
||
| 5216 | * |
||
| 5217 | * @param string $str1 <p> |
||
| 5218 | * The first string. |
||
| 5219 | * </p> |
||
| 5220 | * @param string $str2 <p> |
||
| 5221 | * The second string. |
||
| 5222 | * </p> |
||
| 5223 | * |
||
| 5224 | * @return int Similar to other string comparison functions, this one returns < 0 if |
||
| 5225 | * str1 is less than str2; > |
||
| 5226 | * 0 if str1 is greater than |
||
| 5227 | * str2, and 0 if they are equal. |
||
| 5228 | * @since 4.0 |
||
| 5229 | * @since 5.0 |
||
| 5230 | */ |
||
| 5231 | public static function strnatcmp($str1, $str2) |
||
| 5235 | 1 | ||
| 5236 | /** |
||
| 5237 | 1 | * Binary safe case-insensitive string comparison of the first n characters |
|
| 5238 | * |
||
| 5239 | * @link http://php.net/manual/en/function.strncasecmp.php |
||
| 5240 | * |
||
| 5241 | * @param string $str1 <p> |
||
| 5242 | * The first string. |
||
| 5243 | * </p> |
||
| 5244 | * @param string $str2 <p> |
||
| 5245 | * The second string. |
||
| 5246 | * </p> |
||
| 5247 | * @param int $len <p> |
||
| 5248 | * The length of strings to be used in the comparison. |
||
| 5249 | 1 | * </p> |
|
| 5250 | * |
||
| 5251 | 1 | * @return int < 0 if <i>str1</i> is less than |
|
| 5252 | * <i>str2</i>; > 0 if <i>str1</i> is |
||
| 5253 | * greater than <i>str2</i>, and 0 if they are equal. |
||
| 5254 | * @since 4.0.4 |
||
| 5255 | * @since 5.0 |
||
| 5256 | */ |
||
| 5257 | public static function strncasecmp($str1, $str2, $len) |
||
| 5261 | |||
| 5262 | /** |
||
| 5263 | * Binary safe string comparison of the first n characters |
||
| 5264 | * |
||
| 5265 | * @link http://php.net/manual/en/function.strncmp.php |
||
| 5266 | * |
||
| 5267 | * @param string $str1 <p> |
||
| 5268 | * The first string. |
||
| 5269 | * </p> |
||
| 5270 | * @param string $str2 <p> |
||
| 5271 | * The second string. |
||
| 5272 | * </p> |
||
| 5273 | * @param int $len <p> |
||
| 5274 | * Number of characters to use in the comparison. |
||
| 5275 | * </p> |
||
| 5276 | 10 | * |
|
| 5277 | * @return int < 0 if <i>str1</i> is less than |
||
| 5278 | 10 | * <i>str2</i>; > 0 if <i>str1</i> |
|
| 5279 | 10 | * is greater than <i>str2</i>, and 0 if they are |
|
| 5280 | * equal. |
||
| 5281 | 10 | * @since 4.0 |
|
| 5282 | 2 | * @since 5.0 |
|
| 5283 | */ |
||
| 5284 | public static function strncmp($str1, $str2, $len) |
||
| 5288 | 9 | ||
| 5289 | /** |
||
| 5290 | * Search a string for any of a set of characters |
||
| 5291 | * |
||
| 5292 | 9 | * @link http://php.net/manual/en/function.strpbrk.php |
|
| 5293 | 9 | * |
|
| 5294 | * @param string $haystack <p> |
||
| 5295 | 9 | * The string where char_list is looked for. |
|
| 5296 | * </p> |
||
| 5297 | * @param string $char_list <p> |
||
| 5298 | 1 | * This parameter is case sensitive. |
|
| 5299 | 1 | * </p> |
|
| 5300 | 1 | * |
|
| 5301 | * @return string a string starting from the character found, or false if it is |
||
| 5302 | 9 | * not found. |
|
| 5303 | 9 | * @since 5.0 |
|
| 5304 | */ |
||
| 5305 | public static function strpbrk($haystack, $char_list) |
||
| 5320 | |||
| 5321 | /** |
||
| 5322 | * Find position of first occurrence of string in a string. |
||
| 5323 | * |
||
| 5324 | * @link http://php.net/manual/en/function.mb-strpos.php |
||
| 5325 | * |
||
| 5326 | * @param string $haystack <p> |
||
| 5327 | * The string being checked. |
||
| 5328 | * </p> |
||
| 5329 | * @param string $needle <p> |
||
| 5330 | * The position counted from the beginning of haystack. |
||
| 5331 | * </p> |
||
| 5332 | * @param int $offset [optional] <p> |
||
| 5333 | * The search offset. If it is not specified, 0 is used. |
||
| 5334 | * </p> |
||
| 5335 | * @param string $encoding |
||
| 5336 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string. |
||
| 5337 | * |
||
| 5338 | * @return int The numeric position of the first occurrence of needle in the haystack string.<br /> |
||
| 5339 | 6 | * If needle is not found it returns false. |
|
| 5340 | */ |
||
| 5341 | 6 | public static function strpos($haystack, $needle, $offset = 0, $encoding = 'UTF-8', $cleanUtf8 = false) |
|
| 5397 | |||
| 5398 | 10 | /** |
|
| 5399 | 1 | * Finds the last occurrence of a character in a string within another. |
|
| 5400 | 1 | * |
|
| 5401 | * @link http://php.net/manual/en/function.mb-strrchr.php |
||
| 5402 | * |
||
| 5403 | 10 | * @param string $haystack <p> |
|
| 5404 | 10 | * The string from which to get the last occurrence |
|
| 5405 | * of needle |
||
| 5406 | 10 | * </p> |
|
| 5407 | * @param string $needle <p> |
||
| 5408 | 10 | * The string to find in haystack |
|
| 5409 | * </p> |
||
| 5410 | * @param bool $part [optional] <p> |
||
| 5411 | * Determines which portion of haystack |
||
| 5412 | * this function returns. |
||
| 5413 | * If set to true, it returns all of haystack |
||
| 5414 | * from the beginning to the last occurrence of needle. |
||
| 5415 | * If set to false, it returns all of haystack |
||
| 5416 | * from the last occurrence of needle to the end, |
||
| 5417 | * </p> |
||
| 5418 | * @param string $encoding [optional] <p> |
||
| 5419 | * Character encoding name to use. |
||
| 5420 | * If it is omitted, internal character encoding is used. |
||
| 5421 | * </p> |
||
| 5422 | * |
||
| 5423 | * @return string the portion of haystack. |
||
| 5424 | 20 | * or false if needle is not found. |
|
| 5425 | */ |
||
| 5426 | 20 | public static function strrchr($haystack, $needle, $part = false, $encoding = 'UTF-8') |
|
| 5432 | |||
| 5433 | 18 | /** |
|
| 5434 | * Reverses characters order in the string. |
||
| 5435 | 18 | * |
|
| 5436 | * @param string $str The input string |
||
| 5437 | * |
||
| 5438 | * @return string The string with characters in the reverse sequence |
||
| 5439 | */ |
||
| 5440 | public static function strrev($str) |
||
| 5444 | |||
| 5445 | 3 | /** |
|
| 5446 | * Finds the last occurrence of a character in a string within another, case insensitive. |
||
| 5447 | 3 | * |
|
| 5448 | * @link http://php.net/manual/en/function.mb-strrichr.php |
||
| 5449 | * |
||
| 5450 | * @param string $haystack <p> |
||
| 5451 | * The string from which to get the last occurrence |
||
| 5452 | * of needle |
||
| 5453 | * </p> |
||
| 5454 | * @param string $needle <p> |
||
| 5455 | * The string to find in haystack |
||
| 5456 | * </p> |
||
| 5457 | * @param bool $part [optional] <p> |
||
| 5458 | * Determines which portion of haystack |
||
| 5459 | * this function returns. |
||
| 5460 | * If set to true, it returns all of haystack |
||
| 5461 | * from the beginning to the last occurrence of needle. |
||
| 5462 | 16 | * If set to false, it returns all of haystack |
|
| 5463 | * from the last occurrence of needle to the end, |
||
| 5464 | 16 | * </p> |
|
| 5465 | * @param string $encoding [optional] <p> |
||
| 5466 | 16 | * Character encoding name to use. |
|
| 5467 | 4 | * If it is omitted, internal character encoding is used. |
|
| 5468 | * </p> |
||
| 5469 | * |
||
| 5470 | * @return string the portion of haystack. |
||
| 5471 | 15 | * or false if needle is not found. |
|
| 5472 | */ |
||
| 5473 | 15 | public static function strrichr($haystack, $needle, $part = false, $encoding = 'UTF-8') |
|
| 5479 | |||
| 5480 | /** |
||
| 5481 | * Find position of last occurrence of a case-insensitive string. |
||
| 5482 | * |
||
| 5483 | * @param string $haystack The string to look in |
||
| 5484 | * @param string $needle The string to look for |
||
| 5485 | * @param int $offset (Optional) Number of characters to ignore in the beginning or end |
||
| 5486 | * |
||
| 5487 | * @return int The position of offset |
||
| 5488 | */ |
||
| 5489 | public static function strripos($haystack, $needle, $offset = 0) |
||
| 5493 | |||
| 5494 | /** |
||
| 5495 | * Find position of last occurrence of a string in a string. |
||
| 5496 | * |
||
| 5497 | * @link http://php.net/manual/en/function.mb-strrpos.php |
||
| 5498 | * |
||
| 5499 | * @param string $haystack <p> |
||
| 5500 | * The string being checked, for the last occurrence |
||
| 5501 | * of needle |
||
| 5502 | * </p> |
||
| 5503 | 1 | * @param string|int $needle <p> |
|
| 5504 | * The string to find in haystack. |
||
| 5505 | 1 | * Or a code point as int. |
|
| 5506 | * </p> |
||
| 5507 | * @param int $offset [optional] May be specified to begin searching an arbitrary number of characters into |
||
| 5508 | * the string. Negative values will stop searching at an arbitrary point |
||
| 5509 | * prior to the end of the string. |
||
| 5510 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 5511 | * |
||
| 5512 | * @return int the numeric position of |
||
| 5513 | * the last occurrence of needle in the |
||
| 5514 | * haystack string. If |
||
| 5515 | * needle is not found, it returns false. |
||
| 5516 | */ |
||
| 5517 | public static function strrpos($haystack, $needle, $offset = null, $cleanUtf8 = false) |
||
| 5569 | 37 | ||
| 5570 | /** |
||
| 5571 | * Finds the length of the initial segment of a string consisting entirely of characters contained within a given |
||
| 5572 | * mask. |
||
| 5573 | 1 | * |
|
| 5574 | 1 | * @param string $str |
|
| 5575 | * @param string $mask |
||
| 5576 | 37 | * @param int $offset |
|
| 5577 | 22 | * @param int $length |
|
| 5578 | 22 | * |
|
| 5579 | 33 | * @return int|null |
|
| 5580 | */ |
||
| 5581 | public static function strspn($str, $mask, $offset = 0, $length = 2147483647) |
||
| 5589 | 37 | ||
| 5590 | /** |
||
| 5591 | * Returns part of haystack string from the first occurrence of needle to the end of haystack. |
||
| 5592 | * |
||
| 5593 | * @link http://php.net/manual/en/function.grapheme-strstr.php |
||
| 5594 | * |
||
| 5595 | * @param string $haystack <p> |
||
| 5596 | * The input string. Must be valid UTF-8. |
||
| 5597 | * </p> |
||
| 5598 | * @param string $needle <p> |
||
| 5599 | * The string to look for. Must be valid UTF-8. |
||
| 5600 | * </p> |
||
| 5601 | * @param bool $before_needle [optional] <p> |
||
| 5602 | * If <b>TRUE</b>, grapheme_strstr() returns the part of the |
||
| 5603 | * haystack before the first occurrence of the needle (excluding the needle). |
||
| 5604 | * </p> |
||
| 5605 | * |
||
| 5606 | * @return string the portion of string, or FALSE if needle is not found. |
||
| 5607 | */ |
||
| 5608 | public static function strstr($haystack, $needle, $before_needle = false) |
||
| 5614 | |||
| 5615 | /** |
||
| 5616 | * Unicode transformation for case-less matching. |
||
| 5617 | * |
||
| 5618 | 1 | * @link http://unicode.org/reports/tr21/tr21-5.html |
|
| 5619 | * |
||
| 5620 | 1 | * @param string $str |
|
| 5621 | 1 | * @param bool $full |
|
| 5622 | * |
||
| 5623 | 1 | * @return string |
|
| 5624 | */ |
||
| 5625 | public static function strtocasefold($str, $full = true) |
||
| 5652 | |||
| 5653 | /** |
||
| 5654 | * (PHP 4 >= 4.3.0, PHP 5)<br/> |
||
| 5655 | * Make a string lowercase. |
||
| 5656 | * |
||
| 5657 | * @link http://php.net/manual/en/function.mb-strtolower.php |
||
| 5658 | * |
||
| 5659 | * @param string $str <p> |
||
| 5660 | * The string being lowercased. |
||
| 5661 | * </p> |
||
| 5662 | * @param string $encoding |
||
| 5663 | * |
||
| 5664 | * @return string str with all alphabetic characters converted to lowercase. |
||
| 5665 | 6 | */ |
|
| 5666 | public static function strtolower($str, $encoding = 'UTF-8') |
||
| 5679 | 1 | ||
| 5680 | 1 | /** |
|
| 5681 | 1 | * Generic case sensitive transformation for collation matching. |
|
| 5682 | 1 | * |
|
| 5683 | 1 | * @param string $s |
|
| 5684 | 1 | * |
|
| 5685 | 1 | * @return string |
|
| 5686 | 1 | */ |
|
| 5687 | protected static function strtonatfold($s) |
||
| 5691 | 1 | ||
| 5692 | 1 | /** |
|
| 5693 | 1 | * Make a string uppercase. |
|
| 5694 | 1 | * |
|
| 5695 | 1 | * @link http://php.net/manual/en/function.mb-strtoupper.php |
|
| 5696 | 1 | * |
|
| 5697 | 1 | * @param string $str <p> |
|
| 5698 | * The string being uppercased. |
||
| 5699 | * </p> |
||
| 5700 | 1 | * @param string $encoding |
|
| 5701 | 1 | * |
|
| 5702 | 1 | * @return string str with all alphabetic characters converted to uppercase. |
|
| 5703 | 1 | */ |
|
| 5704 | public static function strtoupper($str, $encoding = 'UTF-8') |
||
| 5735 | |||
| 5736 | /** |
||
| 5737 | * Translate characters or replace sub-strings. |
||
| 5738 | * |
||
| 5739 | * @link http://php.net/manual/en/function.strtr.php |
||
| 5740 | 1 | * |
|
| 5741 | * @param string $str <p> |
||
| 5742 | 1 | * The string being translated. |
|
| 5743 | * </p> |
||
| 5744 | 1 | * @param string|array $from <p> |
|
| 5745 | 1 | * The string replacing from. |
|
| 5746 | * </p> |
||
| 5747 | * @param string|array $to <p> |
||
| 5748 | 1 | * The string being translated to to. |
|
| 5749 | * </p> |
||
| 5750 | 1 | * |
|
| 5751 | 1 | * @return string This function returns a copy of str, |
|
| 5752 | * translating all occurrences of each character in |
||
| 5753 | 1 | * from to the corresponding character in |
|
| 5754 | * to. |
||
| 5755 | 1 | * @since 4.0 |
|
| 5756 | 1 | * @since 5.0 |
|
| 5757 | */ |
||
| 5758 | 1 | public static function strtr($str, $from, $to = INF) |
|
| 5777 | 6 | ||
| 5778 | /** |
||
| 5779 | * Return the width of a string. |
||
| 5780 | * |
||
| 5781 | * @param string $s |
||
| 5782 | * |
||
| 5783 | * @return int |
||
| 5784 | */ |
||
| 5785 | public static function strwidth($s) |
||
| 5792 | |||
| 5793 | /** |
||
| 5794 | * Get part of a string. |
||
| 5795 | * |
||
| 5796 | * @link http://php.net/manual/en/function.mb-substr.php |
||
| 5797 | * |
||
| 5798 | * @param string $str <p> |
||
| 5799 | * The string being checked. |
||
| 5800 | * </p> |
||
| 5801 | * @param int $start <p> |
||
| 5802 | * The first position used in str. |
||
| 5803 | * </p> |
||
| 5804 | * @param int $length [optional] <p> |
||
| 5805 | * The maximum length of the returned string. |
||
| 5806 | * </p> |
||
| 5807 | * @param string $encoding |
||
| 5808 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 5809 | * |
||
| 5810 | * @return string mb_substr returns the portion of |
||
| 5811 | * str specified by the start and length parameters. |
||
| 5812 | 7 | */ |
|
| 5813 | public static function substr($str, $start = 0, $length = null, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 5859 | 1 | ||
| 5860 | 1 | /** |
|
| 5861 | 1 | * Binary safe comparison of two strings from an offset, up to length characters. |
|
| 5862 | * |
||
| 5863 | 1 | * @param string $main_str The main string being compared. |
|
| 5864 | * @param string $str The secondary string being compared. |
||
| 5865 | * @param int $offset The start position for the comparison. If negative, it starts counting from the |
||
| 5866 | 1 | * end of the string. |
|
| 5867 | * @param int $length The length of the comparison. The default value is the largest of the length of |
||
| 5868 | * the str compared to the length of main_str less the offset. |
||
| 5869 | 1 | * @param boolean $case_insensitivity If case_insensitivity is TRUE, comparison is case insensitive. |
|
| 5870 | * |
||
| 5871 | 3 | * @return int |
|
| 5872 | 1 | */ |
|
| 5873 | 1 | public static function substr_compare($main_str, $str, $offset, $length = 2147483647, $case_insensitivity = false) |
|
| 5880 | |||
| 5881 | 6 | /** |
|
| 5882 | * Count the number of substring occurrences |
||
| 5883 | * |
||
| 5884 | * @link http://php.net/manual/en/function.substr-count.php |
||
| 5885 | * |
||
| 5886 | * @param string $haystack <p> |
||
| 5887 | * The string to search in |
||
| 5888 | * </p> |
||
| 5889 | * @param string $needle <p> |
||
| 5890 | * The substring to search for |
||
| 5891 | * </p> |
||
| 5892 | * @param int $offset [optional] <p> |
||
| 5893 | * The offset where to start counting |
||
| 5894 | * </p> |
||
| 5895 | * @param int $length [optional] <p> |
||
| 5896 | * The maximum length after the specified offset to search for the |
||
| 5897 | * substring. It outputs a warning if the offset plus the length is |
||
| 5898 | * greater than the haystack length. |
||
| 5899 | * </p> |
||
| 5900 | * |
||
| 5901 | * @return int This functions returns an integer. |
||
| 5902 | * @since 4.0 |
||
| 5903 | 2 | * @since 5.0 |
|
| 5904 | */ |
||
| 5905 | 2 | public static function substr_count($haystack, $needle, $offset = 0, $length = null) |
|
| 5925 | |||
| 5926 | /** |
||
| 5927 | * Replace text within a portion of a string. |
||
| 5928 | * |
||
| 5929 | 20 | * source: https://gist.github.com/stemar/8287074 |
|
| 5930 | * |
||
| 5931 | 20 | * @param string|array $str |
|
| 5932 | 2 | * @param string|array $replacement |
|
| 5933 | * @param int|array $start |
||
| 5934 | 2 | * @param null|int|array $length |
|
| 5935 | 2 | * |
|
| 5936 | * @return array|string |
||
| 5937 | 2 | */ |
|
| 5938 | public static function substr_replace($str, $replacement, $start, $length = null) |
||
| 6003 | 2 | ||
| 6004 | 2 | /** |
|
| 6005 | 2 | * Returns a case swapped version of the string. |
|
| 6006 | * |
||
| 6007 | * @param string $str |
||
| 6008 | 2 | * @param string $encoding |
|
| 6009 | 18 | * |
|
| 6010 | * @return string each character's case swapped |
||
| 6011 | 20 | */ |
|
| 6012 | public static function swapCase($str, $encoding = 'UTF-8') |
||
| 6038 | |||
| 6039 | /** |
||
| 6040 | * alias for "UTF8::to_ascii()" |
||
| 6041 | * |
||
| 6042 | * @param string $s The input string e.g. a UTF-8 String |
||
| 6043 | 2 | * @param string $subst_chr |
|
| 6044 | * |
||
| 6045 | 2 | * @return string |
|
| 6046 | */ |
||
| 6047 | 1 | public static function toAscii($s, $subst_chr = '?') |
|
| 6051 | |||
| 6052 | 1 | /** |
|
| 6053 | 2 | * alias for "UTF8::to_latin1()" |
|
| 6054 | 2 | * |
|
| 6055 | * @param $str |
||
| 6056 | * |
||
| 6057 | * @return string |
||
| 6058 | */ |
||
| 6059 | public static function toLatin1($str) |
||
| 6063 | |||
| 6064 | /** |
||
| 6065 | * alias for "UTF8::to_utf8" |
||
| 6066 | * |
||
| 6067 | * @param string $str |
||
| 6068 | * |
||
| 6069 | * @return string |
||
| 6070 | */ |
||
| 6071 | public static function toUTF8($str) |
||
| 6075 | 26 | ||
| 6076 | /** |
||
| 6077 | 26 | * convert to ASCII |
|
| 6078 | 5 | * |
|
| 6079 | * @param string $s The input string e.g. a UTF-8 String |
||
| 6080 | * @param string $subst_chr |
||
| 6081 | * |
||
| 6082 | 22 | * @return string |
|
| 6083 | 6 | */ |
|
| 6084 | public static function to_ascii($s, $subst_chr = '?') |
||
| 6155 | |||
| 6156 | /** |
||
| 6157 | * alias for "UTF8::to_win1252()" |
||
| 6158 | * |
||
| 6159 | * @param string $str |
||
| 6160 | * |
||
| 6161 | * @return array|string |
||
| 6162 | */ |
||
| 6163 | public static function to_iso8859($str) |
||
| 6167 | |||
| 6168 | /** |
||
| 6169 | * alias for "UTF8::to_win1252()" |
||
| 6170 | * |
||
| 6171 | * @param string|array $str |
||
| 6172 | 1 | * |
|
| 6173 | * @return string|array |
||
| 6174 | 1 | */ |
|
| 6175 | public static function to_latin1($str) |
||
| 6179 | |||
| 6180 | 1 | /** |
|
| 6181 | * This function leaves UTF8 characters alone, while converting almost all non-UTF8 to UTF8. |
||
| 6182 | 1 | * |
|
| 6183 | * - It assumes that the encoding of the original string is either WINDOWS-1252 or ISO-8859-1. |
||
| 6184 | 1 | * |
|
| 6185 | 1 | * - It may fail to convert characters to UTF-8 if they fall into one of these scenarios: |
|
| 6186 | 1 | * |
|
| 6187 | 1 | * 1) when any of these characters: ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß |
|
| 6188 | * are followed by any of these: ("group B") |
||
| 6189 | 1 | * ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶•¸¹º»¼½¾¿ |
|
| 6190 | 1 | * For example: %ABREPRESENT%C9%BB. «REPRESENTÉ» |
|
| 6191 | 1 | * The "«" (%AB) character will be converted, but the "É" followed by "»" (%C9%BB) |
|
| 6192 | * is also a valid unicode character, and will be left unchanged. |
||
| 6193 | 1 | * |
|
| 6194 | * 2) when any of these: àáâãäåæçèéêëìíîï are followed by TWO chars from group B, |
||
| 6195 | * 3) when any of these: ðñòó are followed by THREE chars from group B. |
||
| 6196 | * |
||
| 6197 | * @param string|array $str Any string or array. |
||
| 6198 | * |
||
| 6199 | * @return string The same string, but UTF8 encoded. |
||
| 6200 | */ |
||
| 6201 | public static function to_utf8($str) |
||
| 6307 | |||
| 6308 | /** |
||
| 6309 | * Convert a string into "win1252"-encoding. |
||
| 6310 | * |
||
| 6311 | * @param string|array $str |
||
| 6312 | * |
||
| 6313 | * @return string|array |
||
| 6314 | */ |
||
| 6315 | protected static function to_win1252($str) |
||
| 6335 | |||
| 6336 | /** |
||
| 6337 | * Strip whitespace or other characters from beginning or end of a UTF-8 string. |
||
| 6338 | * |
||
| 6339 | * INFO: This is slower then "trim()" |
||
| 6340 | * |
||
| 6341 | * But we can only use the original-function, if we use <= 7-Bit in the string / chars |
||
| 6342 | * but the check for ACSII (7-Bit) cost more time, then we can safe here. |
||
| 6343 | * |
||
| 6344 | * @param string $str The string to be trimmed |
||
| 6345 | * @param string $chars Optional characters to be stripped |
||
| 6346 | * |
||
| 6347 | * @return string The trimmed string |
||
| 6348 | */ |
||
| 6349 | public static function trim($str = '', $chars = INF) |
||
| 6364 | |||
| 6365 | /** |
||
| 6366 | * Makes string's first char uppercase. |
||
| 6367 | * |
||
| 6368 | * @param string $str The input string |
||
| 6369 | * |
||
| 6370 | * @return string The resulting string |
||
| 6371 | */ |
||
| 6372 | public static function ucfirst($str) |
||
| 6376 | |||
| 6377 | /** |
||
| 6378 | * alias for "UTF8::ucfirst" |
||
| 6379 | * |
||
| 6380 | * @param $str |
||
| 6381 | * |
||
| 6382 | * @return string |
||
| 6383 | */ |
||
| 6384 | public static function ucword($str) |
||
| 6388 | |||
| 6389 | /** |
||
| 6390 | * Uppercase for all words in the string. |
||
| 6391 | * |
||
| 6392 | * @param string $str |
||
| 6393 | * @param array $exceptions |
||
| 6394 | * |
||
| 6395 | * @return string |
||
| 6396 | */ |
||
| 6397 | public static function ucwords($str, $exceptions = array()) |
||
| 6430 | |||
| 6431 | /** |
||
| 6432 | * Multi decode html entity & fix urlencoded-win1252-chars. |
||
| 6433 | * |
||
| 6434 | * e.g: |
||
| 6435 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 6436 | * 'D%FCsseldorf' => 'Düsseldorf' |
||
| 6437 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 6438 | * 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' |
||
| 6439 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 6440 | 6 | * 'D%C3%BCsseldorf' => 'Düsseldorf' |
|
| 6441 | * 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' |
||
| 6442 | 6 | * 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf' |
|
| 6443 | 6 | * |
|
| 6444 | * @param string $str |
||
| 6445 | 6 | * |
|
| 6446 | * @return string |
||
| 6447 | 6 | */ |
|
| 6448 | 5 | public static function urldecode($str) |
|
| 6471 | 6 | ||
| 6472 | /** |
||
| 6473 | 6 | * Return a array with "urlencoded"-win1252 -> UTF-8 |
|
| 6474 | * |
||
| 6475 | 6 | * @return mixed |
|
| 6476 | 6 | */ |
|
| 6477 | public static function urldecode_fix_win1252_chars() |
||
| 6708 | |||
| 6709 | /** |
||
| 6710 | * Decodes an UTF-8 string to ISO-8859-1. |
||
| 6711 | * |
||
| 6712 | * @param string $str |
||
| 6713 | * |
||
| 6714 | * @return string |
||
| 6715 | */ |
||
| 6716 | public static function utf8_decode($str) |
||
| 6739 | |||
| 6740 | /** |
||
| 6741 | * Encodes an ISO-8859-1 string to UTF-8. |
||
| 6742 | * |
||
| 6743 | * @param string $str |
||
| 6744 | * |
||
| 6745 | * @return string |
||
| 6746 | */ |
||
| 6747 | public static function utf8_encode($str) |
||
| 6766 | |||
| 6767 | /** |
||
| 6768 | * fix -> utf8-win1252 chars |
||
| 6769 | * |
||
| 6770 | * If you received an UTF-8 string that was converted from Windows-1252 as it was ISO-8859-1 |
||
| 6771 | * (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. |
||
| 6772 | * See: http://en.wikipedia.org/wiki/Windows-1252 |
||
| 6773 | * |
||
| 6774 | * @deprecated use "UTF8::fix_simple_utf8()" |
||
| 6775 | * |
||
| 6776 | * @param string $str |
||
| 6777 | * |
||
| 6778 | * @return string |
||
| 6779 | */ |
||
| 6780 | public static function utf8_fix_win1252_chars($str) |
||
| 6784 | |||
| 6785 | /** |
||
| 6786 | * Returns an array with all utf8 whitespace characters. |
||
| 6787 | * |
||
| 6788 | * @see : http://www.bogofilter.org/pipermail/bogofilter/2003-March/001889.html |
||
| 6789 | * |
||
| 6790 | * @author: Derek E. [email protected] |
||
| 6791 | * |
||
| 6792 | * @return array an array with all known whitespace characters as values and the type of whitespace as keys |
||
| 6793 | * as defined in above URL |
||
| 6794 | */ |
||
| 6795 | public static function whitespace_table() |
||
| 6799 | |||
| 6800 | /** |
||
| 6801 | * Limit the number of words in a string. |
||
| 6802 | * |
||
| 6803 | * @param string $str |
||
| 6804 | * @param int $words |
||
| 6805 | * @param string $strAddOn |
||
| 6806 | * |
||
| 6807 | * @return string |
||
| 6808 | */ |
||
| 6809 | public static function words_limit($str, $words = 100, $strAddOn = '...') |
||
| 6835 | |||
| 6836 | /** |
||
| 6837 | * Wraps a string to a given number of characters |
||
| 6838 | * |
||
| 6839 | * @link http://php.net/manual/en/function.wordwrap.php |
||
| 6840 | * |
||
| 6841 | * @param string $str <p> |
||
| 6842 | * The input string. |
||
| 6843 | * </p> |
||
| 6844 | * @param int $width [optional] <p> |
||
| 6845 | * The column width. |
||
| 6846 | * </p> |
||
| 6847 | * @param string $break [optional] <p> |
||
| 6848 | * The line is broken using the optional |
||
| 6849 | * break parameter. |
||
| 6850 | * </p> |
||
| 6851 | * @param bool $cut [optional] <p> |
||
| 6852 | * If the cut is set to true, the string is |
||
| 6853 | * always wrapped at or before the specified width. So if you have |
||
| 6854 | * a word that is larger than the given width, it is broken apart. |
||
| 6855 | * (See second example). |
||
| 6856 | * </p> |
||
| 6857 | * |
||
| 6858 | * @return string the given string wrapped at the specified column. |
||
| 6859 | * @since 4.0.2 |
||
| 6860 | * @since 5.0 |
||
| 6861 | */ |
||
| 6862 | public static function wordwrap($str, $width = 75, $break = "\n", $cut = false) |
||
| 6917 | |||
| 6918 | /** |
||
| 6919 | * Returns an array of Unicode White Space characters. |
||
| 6920 | * |
||
| 6921 | * @return array An array with numeric code point as key and White Space Character as value. |
||
| 6922 | */ |
||
| 6923 | public static function ws() |
||
| 6927 | |||
| 6928 | } |
||
| 6929 |
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: