Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like UTF8 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UTF8, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class UTF8 |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | protected static $win1252ToUtf8 = array( |
||
| 20 | 128 => "\xe2\x82\xac", // EURO SIGN |
||
| 21 | 130 => "\xe2\x80\x9a", // SINGLE LOW-9 QUOTATION MARK |
||
| 22 | 131 => "\xc6\x92", // LATIN SMALL LETTER F WITH HOOK |
||
| 23 | 132 => "\xe2\x80\x9e", // DOUBLE LOW-9 QUOTATION MARK |
||
| 24 | 133 => "\xe2\x80\xa6", // HORIZONTAL ELLIPSIS |
||
| 25 | 134 => "\xe2\x80\xa0", // DAGGER |
||
| 26 | 135 => "\xe2\x80\xa1", // DOUBLE DAGGER |
||
| 27 | 136 => "\xcb\x86", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 28 | 137 => "\xe2\x80\xb0", // PER MILLE SIGN |
||
| 29 | 138 => "\xc5\xa0", // LATIN CAPITAL LETTER S WITH CARON |
||
| 30 | 139 => "\xe2\x80\xb9", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 31 | 140 => "\xc5\x92", // LATIN CAPITAL LIGATURE OE |
||
| 32 | 142 => "\xc5\xbd", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 33 | 145 => "\xe2\x80\x98", // LEFT SINGLE QUOTATION MARK |
||
| 34 | 146 => "\xe2\x80\x99", // RIGHT SINGLE QUOTATION MARK |
||
| 35 | 147 => "\xe2\x80\x9c", // LEFT DOUBLE QUOTATION MARK |
||
| 36 | 148 => "\xe2\x80\x9d", // RIGHT DOUBLE QUOTATION MARK |
||
| 37 | 149 => "\xe2\x80\xa2", // BULLET |
||
| 38 | 150 => "\xe2\x80\x93", // EN DASH |
||
| 39 | 151 => "\xe2\x80\x94", // EM DASH |
||
| 40 | 152 => "\xcb\x9c", // SMALL TILDE |
||
| 41 | 153 => "\xe2\x84\xa2", // TRADE MARK SIGN |
||
| 42 | 154 => "\xc5\xa1", // LATIN SMALL LETTER S WITH CARON |
||
| 43 | 155 => "\xe2\x80\xba", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 44 | 156 => "\xc5\x93", // LATIN SMALL LIGATURE OE |
||
| 45 | 158 => "\xc5\xbe", // LATIN SMALL LETTER Z WITH CARON |
||
| 46 | 159 => "\xc5\xb8", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
||
| 47 | ); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var array |
||
| 51 | */ |
||
| 52 | protected static $cp1252ToUtf8 = array( |
||
| 53 | '' => '€', |
||
| 54 | '' => '‚', |
||
| 55 | '' => 'ƒ', |
||
| 56 | '' => '„', |
||
| 57 | ' ' => '…', |
||
| 58 | '' => '†', |
||
| 59 | '' => '‡', |
||
| 60 | '' => 'ˆ', |
||
| 61 | '' => '‰', |
||
| 62 | '' => 'Š', |
||
| 63 | '' => '‹', |
||
| 64 | '' => 'Œ', |
||
| 65 | '' => 'Ž', |
||
| 66 | '' => '‘', |
||
| 67 | '' => '’', |
||
| 68 | '' => '“', |
||
| 69 | '' => '”', |
||
| 70 | '' => '•', |
||
| 71 | '' => '–', |
||
| 72 | '' => '—', |
||
| 73 | '' => '˜', |
||
| 74 | '' => '™', |
||
| 75 | '' => 'š', |
||
| 76 | '' => '›', |
||
| 77 | '' => 'œ', |
||
| 78 | '' => 'ž', |
||
| 79 | '' => 'Ÿ', |
||
| 80 | ); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Numeric code point => UTF-8 Character |
||
| 84 | * |
||
| 85 | * url: http://www.w3schools.com/charsets/ref_utf_punctuation.asp |
||
| 86 | * |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | protected static $whitespace = array( |
||
| 90 | // NUL Byte |
||
| 91 | 0 => "\x0", |
||
| 92 | // Tab |
||
| 93 | 9 => "\x9", |
||
| 94 | // New Line |
||
| 95 | 10 => "\xa", |
||
| 96 | // Vertical Tab |
||
| 97 | 11 => "\xb", |
||
| 98 | // Carriage Return |
||
| 99 | 13 => "\xd", |
||
| 100 | // Ordinary Space |
||
| 101 | 32 => "\x20", |
||
| 102 | // NO-BREAK SPACE |
||
| 103 | 160 => "\xc2\xa0", |
||
| 104 | // OGHAM SPACE MARK |
||
| 105 | 5760 => "\xe1\x9a\x80", |
||
| 106 | // MONGOLIAN VOWEL SEPARATOR |
||
| 107 | 6158 => "\xe1\xa0\x8e", |
||
| 108 | // EN QUAD |
||
| 109 | 8192 => "\xe2\x80\x80", |
||
| 110 | // EM QUAD |
||
| 111 | 8193 => "\xe2\x80\x81", |
||
| 112 | // EN SPACE |
||
| 113 | 8194 => "\xe2\x80\x82", |
||
| 114 | // EM SPACE |
||
| 115 | 8195 => "\xe2\x80\x83", |
||
| 116 | // THREE-PER-EM SPACE |
||
| 117 | 8196 => "\xe2\x80\x84", |
||
| 118 | // FOUR-PER-EM SPACE |
||
| 119 | 8197 => "\xe2\x80\x85", |
||
| 120 | // SIX-PER-EM SPACE |
||
| 121 | 8198 => "\xe2\x80\x86", |
||
| 122 | // FIGURE SPACE |
||
| 123 | 8199 => "\xe2\x80\x87", |
||
| 124 | // PUNCTUATION SPACE |
||
| 125 | 8200 => "\xe2\x80\x88", |
||
| 126 | // THIN SPACE |
||
| 127 | 8201 => "\xe2\x80\x89", |
||
| 128 | //HAIR SPACE |
||
| 129 | 8202 => "\xe2\x80\x8a", |
||
| 130 | // LINE SEPARATOR |
||
| 131 | 8232 => "\xe2\x80\xa8", |
||
| 132 | // PARAGRAPH SEPARATOR |
||
| 133 | 8233 => "\xe2\x80\xa9", |
||
| 134 | // NARROW NO-BREAK SPACE |
||
| 135 | 8239 => "\xe2\x80\xaf", |
||
| 136 | // MEDIUM MATHEMATICAL SPACE |
||
| 137 | 8287 => "\xe2\x81\x9f", |
||
| 138 | // IDEOGRAPHIC SPACE |
||
| 139 | 12288 => "\xe3\x80\x80", |
||
| 140 | ); |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @var array |
||
| 144 | */ |
||
| 145 | protected static $whitespaceTable = array( |
||
| 146 | 'SPACE' => "\x20", |
||
| 147 | 'NO-BREAK SPACE' => "\xc2\xa0", |
||
| 148 | 'OGHAM SPACE MARK' => "\xe1\x9a\x80", |
||
| 149 | 'EN QUAD' => "\xe2\x80\x80", |
||
| 150 | 'EM QUAD' => "\xe2\x80\x81", |
||
| 151 | 'EN SPACE' => "\xe2\x80\x82", |
||
| 152 | 'EM SPACE' => "\xe2\x80\x83", |
||
| 153 | 'THREE-PER-EM SPACE' => "\xe2\x80\x84", |
||
| 154 | 'FOUR-PER-EM SPACE' => "\xe2\x80\x85", |
||
| 155 | 'SIX-PER-EM SPACE' => "\xe2\x80\x86", |
||
| 156 | 'FIGURE SPACE' => "\xe2\x80\x87", |
||
| 157 | 'PUNCTUATION SPACE' => "\xe2\x80\x88", |
||
| 158 | 'THIN SPACE' => "\xe2\x80\x89", |
||
| 159 | 'HAIR SPACE' => "\xe2\x80\x8a", |
||
| 160 | 'LINE SEPARATOR' => "\xe2\x80\xa8", |
||
| 161 | 'PARAGRAPH SEPARATOR' => "\xe2\x80\xa9", |
||
| 162 | 'ZERO WIDTH SPACE' => "\xe2\x80\x8b", |
||
| 163 | 'NARROW NO-BREAK SPACE' => "\xe2\x80\xaf", |
||
| 164 | 'MEDIUM MATHEMATICAL SPACE' => "\xe2\x81\x9f", |
||
| 165 | 'IDEOGRAPHIC SPACE' => "\xe3\x80\x80", |
||
| 166 | ); |
||
| 167 | |||
| 168 | /** |
||
| 169 | * bidirectional text chars |
||
| 170 | * |
||
| 171 | * url: https://www.w3.org/International/questions/qa-bidi-unicode-controls |
||
| 172 | * |
||
| 173 | * @var array |
||
| 174 | */ |
||
| 175 | protected static $bidiUniCodeControlsTable = array( |
||
| 176 | // LEFT-TO-RIGHT EMBEDDING (use -> dir = "ltr") |
||
| 177 | 8234 => "\xE2\x80\xAA", |
||
| 178 | // RIGHT-TO-LEFT EMBEDDING (use -> dir = "rtl") |
||
| 179 | 8235 => "\xE2\x80\xAB", |
||
| 180 | // POP DIRECTIONAL FORMATTING // (use -> </bdo>) |
||
| 181 | 8236 => "\xE2\x80\xAC", |
||
| 182 | // LEFT-TO-RIGHT OVERRIDE // (use -> <bdo dir = "ltr">) |
||
| 183 | 8237 => "\xE2\x80\xAD", |
||
| 184 | // RIGHT-TO-LEFT OVERRIDE // (use -> <bdo dir = "rtl">) |
||
| 185 | 8238 => "\xE2\x80\xAE", |
||
| 186 | // LEFT-TO-RIGHT ISOLATE // (use -> dir = "ltr") |
||
| 187 | 8294 => "\xE2\x81\xA6", |
||
| 188 | // RIGHT-TO-LEFT ISOLATE // (use -> dir = "rtl") |
||
| 189 | 8295 => "\xE2\x81\xA7", |
||
| 190 | // FIRST STRONG ISOLATE // (use -> dir = "auto") |
||
| 191 | 8296 => "\xE2\x81\xA8", |
||
| 192 | // POP DIRECTIONAL ISOLATE |
||
| 193 | 8297 => "\xE2\x81\xA9", |
||
| 194 | ); |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @var array |
||
| 198 | */ |
||
| 199 | protected static $commonCaseFold = array( |
||
| 200 | 'ſ' => 's', |
||
| 201 | "\xCD\x85" => 'ι', |
||
| 202 | 'ς' => 'σ', |
||
| 203 | "\xCF\x90" => 'β', |
||
| 204 | "\xCF\x91" => 'θ', |
||
| 205 | "\xCF\x95" => 'φ', |
||
| 206 | "\xCF\x96" => 'π', |
||
| 207 | "\xCF\xB0" => 'κ', |
||
| 208 | "\xCF\xB1" => 'ρ', |
||
| 209 | "\xCF\xB5" => 'ε', |
||
| 210 | "\xE1\xBA\x9B" => "\xE1\xB9\xA1", |
||
| 211 | "\xE1\xBE\xBE" => 'ι', |
||
| 212 | ); |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @var array |
||
| 216 | */ |
||
| 217 | protected static $brokenUtf8ToUtf8 = array( |
||
| 218 | "\xc2\x80" => "\xe2\x82\xac", // EURO SIGN |
||
| 219 | "\xc2\x82" => "\xe2\x80\x9a", // SINGLE LOW-9 QUOTATION MARK |
||
| 220 | "\xc2\x83" => "\xc6\x92", // LATIN SMALL LETTER F WITH HOOK |
||
| 221 | "\xc2\x84" => "\xe2\x80\x9e", // DOUBLE LOW-9 QUOTATION MARK |
||
| 222 | "\xc2\x85" => "\xe2\x80\xa6", // HORIZONTAL ELLIPSIS |
||
| 223 | "\xc2\x86" => "\xe2\x80\xa0", // DAGGER |
||
| 224 | "\xc2\x87" => "\xe2\x80\xa1", // DOUBLE DAGGER |
||
| 225 | "\xc2\x88" => "\xcb\x86", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 226 | "\xc2\x89" => "\xe2\x80\xb0", // PER MILLE SIGN |
||
| 227 | "\xc2\x8a" => "\xc5\xa0", // LATIN CAPITAL LETTER S WITH CARON |
||
| 228 | "\xc2\x8b" => "\xe2\x80\xb9", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 229 | "\xc2\x8c" => "\xc5\x92", // LATIN CAPITAL LIGATURE OE |
||
| 230 | "\xc2\x8e" => "\xc5\xbd", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 231 | "\xc2\x91" => "\xe2\x80\x98", // LEFT SINGLE QUOTATION MARK |
||
| 232 | "\xc2\x92" => "\xe2\x80\x99", // RIGHT SINGLE QUOTATION MARK |
||
| 233 | "\xc2\x93" => "\xe2\x80\x9c", // LEFT DOUBLE QUOTATION MARK |
||
| 234 | "\xc2\x94" => "\xe2\x80\x9d", // RIGHT DOUBLE QUOTATION MARK |
||
| 235 | "\xc2\x95" => "\xe2\x80\xa2", // BULLET |
||
| 236 | "\xc2\x96" => "\xe2\x80\x93", // EN DASH |
||
| 237 | "\xc2\x97" => "\xe2\x80\x94", // EM DASH |
||
| 238 | "\xc2\x98" => "\xcb\x9c", // SMALL TILDE |
||
| 239 | "\xc2\x99" => "\xe2\x84\xa2", // TRADE MARK SIGN |
||
| 240 | "\xc2\x9a" => "\xc5\xa1", // LATIN SMALL LETTER S WITH CARON |
||
| 241 | "\xc2\x9b" => "\xe2\x80\xba", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 242 | "\xc2\x9c" => "\xc5\x93", // LATIN SMALL LIGATURE OE |
||
| 243 | "\xc2\x9e" => "\xc5\xbe", // LATIN SMALL LETTER Z WITH CARON |
||
| 244 | "\xc2\x9f" => "\xc5\xb8", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
||
| 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 | /** |
||
| 306 | * @var array |
||
| 307 | */ |
||
| 308 | protected static $utf8ToWin1252 = array( |
||
| 309 | "\xe2\x82\xac" => "\x80", // EURO SIGN |
||
| 310 | "\xe2\x80\x9a" => "\x82", // SINGLE LOW-9 QUOTATION MARK |
||
| 311 | "\xc6\x92" => "\x83", // LATIN SMALL LETTER F WITH HOOK |
||
| 312 | "\xe2\x80\x9e" => "\x84", // DOUBLE LOW-9 QUOTATION MARK |
||
| 313 | "\xe2\x80\xa6" => "\x85", // HORIZONTAL ELLIPSIS |
||
| 314 | "\xe2\x80\xa0" => "\x86", // DAGGER |
||
| 315 | "\xe2\x80\xa1" => "\x87", // DOUBLE DAGGER |
||
| 316 | "\xcb\x86" => "\x88", // MODIFIER LETTER CIRCUMFLEX ACCENT |
||
| 317 | "\xe2\x80\xb0" => "\x89", // PER MILLE SIGN |
||
| 318 | "\xc5\xa0" => "\x8a", // LATIN CAPITAL LETTER S WITH CARON |
||
| 319 | "\xe2\x80\xb9" => "\x8b", // SINGLE LEFT-POINTING ANGLE QUOTE |
||
| 320 | "\xc5\x92" => "\x8c", // LATIN CAPITAL LIGATURE OE |
||
| 321 | "\xc5\xbd" => "\x8e", // LATIN CAPITAL LETTER Z WITH CARON |
||
| 322 | "\xe2\x80\x98" => "\x91", // LEFT SINGLE QUOTATION MARK |
||
| 323 | "\xe2\x80\x99" => "\x92", // RIGHT SINGLE QUOTATION MARK |
||
| 324 | "\xe2\x80\x9c" => "\x93", // LEFT DOUBLE QUOTATION MARK |
||
| 325 | "\xe2\x80\x9d" => "\x94", // RIGHT DOUBLE QUOTATION MARK |
||
| 326 | "\xe2\x80\xa2" => "\x95", // BULLET |
||
| 327 | "\xe2\x80\x93" => "\x96", // EN DASH |
||
| 328 | "\xe2\x80\x94" => "\x97", // EM DASH |
||
| 329 | "\xcb\x9c" => "\x98", // SMALL TILDE |
||
| 330 | "\xe2\x84\xa2" => "\x99", // TRADE MARK SIGN |
||
| 331 | "\xc5\xa1" => "\x9a", // LATIN SMALL LETTER S WITH CARON |
||
| 332 | "\xe2\x80\xba" => "\x9b", // SINGLE RIGHT-POINTING ANGLE QUOTE |
||
| 333 | "\xc5\x93" => "\x9c", // LATIN SMALL LIGATURE OE |
||
| 334 | "\xc5\xbe" => "\x9e", // LATIN SMALL LETTER Z WITH CARON |
||
| 335 | 1 | "\xc5\xb8" => "\x9f", // LATIN CAPITAL LETTER Y WITH DIAERESIS |
|
| 336 | ); |
||
| 337 | 1 | ||
| 338 | 1 | /** |
|
| 339 | * @var array |
||
| 340 | */ |
||
| 341 | protected static $utf8MSWord = array( |
||
| 342 | "\xc2\xab" => '"', // « (U+00AB) in UTF-8 |
||
| 343 | 151 | "\xc2\xbb" => '"', // » (U+00BB) in UTF-8 |
|
| 344 | "\xe2\x80\x98" => "'", // ‘ (U+2018) in UTF-8 |
||
| 345 | 151 | "\xe2\x80\x99" => "'", // ’ (U+2019) in UTF-8 |
|
| 346 | "\xe2\x80\x9a" => "'", // ‚ (U+201A) in UTF-8 |
||
| 347 | 1 | "\xe2\x80\x9b" => "'", // ‛ (U+201B) in UTF-8 |
|
| 348 | 1 | "\xe2\x80\x9c" => '"', // “ (U+201C) in UTF-8 |
|
| 349 | 1 | "\xe2\x80\x9d" => '"', // ” (U+201D) in UTF-8 |
|
| 350 | 1 | "\xe2\x80\x9e" => '"', // „ (U+201E) in UTF-8 |
|
| 351 | "\xe2\x80\x9f" => '"', // ‟ (U+201F) in UTF-8 |
||
| 352 | 1 | "\xe2\x80\xb9" => "'", // ‹ (U+2039) in UTF-8 |
|
| 353 | 1 | "\xe2\x80\xba" => "'", // › (U+203A) in UTF-8 |
|
| 354 | 1 | "\xe2\x80\x93" => '-', // – (U+2013) in UTF-8 |
|
| 355 | 1 | "\xe2\x80\x94" => '-', // — (U+2014) in UTF-8 |
|
| 356 | 151 | "\xe2\x80\xa6" => '...' // … (U+2026) in UTF-8 |
|
| 357 | ); |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @var array |
||
| 361 | */ |
||
| 362 | private static $support = array(); |
||
| 363 | 2 | ||
| 364 | /** |
||
| 365 | 2 | * __construct() |
|
| 366 | */ |
||
| 367 | 2 | public function __construct() |
|
| 371 | 2 | ||
| 372 | /** |
||
| 373 | * Returns a single UTF-8 character from string. |
||
| 374 | * |
||
| 375 | * @param string $str A UTF-8 string. |
||
| 376 | * @param int $pos The position of character to return. |
||
| 377 | * |
||
| 378 | * @return string Single Multi-Byte character. |
||
| 379 | 1 | */ |
|
| 380 | public static function access($str, $pos) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Prepends BOM character to the string and returns the whole string. |
||
| 389 | 1 | * |
|
| 390 | * INFO: If BOM already existed there, the Input string is returned. |
||
| 391 | 1 | * |
|
| 392 | * @param string $str The input string |
||
| 393 | * |
||
| 394 | * @return string The output string that contains BOM |
||
| 395 | */ |
||
| 396 | public static function add_bom_to_string($str) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Returns the Byte Order Mark Character. |
||
| 407 | * |
||
| 408 | * @return string Byte Order Mark |
||
| 409 | */ |
||
| 410 | public static function bom() |
||
| 414 | |||
| 415 | 6 | /** |
|
| 416 | * @alias of UTF8::chr_map() |
||
| 417 | * |
||
| 418 | * @param $callback |
||
| 419 | * @param $str |
||
| 420 | * |
||
| 421 | * @return array |
||
| 422 | */ |
||
| 423 | public static function callback($callback, $str) |
||
| 427 | |||
| 428 | 7 | /** |
|
| 429 | * Returns an array of all lower and upper case UTF-8 encoded characters. |
||
| 430 | 7 | * |
|
| 431 | * @return string An array with lower case chars as keys and upper chars as values. |
||
| 432 | 7 | */ |
|
| 433 | 2 | protected static function case_table() |
|
| 1434 | 40 | ||
| 1435 | /** |
||
| 1436 | 40 | * check for UTF8-Support |
|
| 1437 | 30 | */ |
|
| 1438 | public static function checkForSupport() |
||
| 1448 | 1 | ||
| 1449 | 1 | /** |
|
| 1450 | * Generates a UTF-8 encoded character from the given code point. |
||
| 1451 | * |
||
| 1452 | 16 | * @param int $code_point The code point for which to generate a character. |
|
| 1453 | * |
||
| 1454 | 16 | * @return string Multi-Byte character, returns empty string on failure to encode. |
|
| 1455 | */ |
||
| 1456 | 16 | public static function chr($code_point) |
|
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Applies callback to all characters of a string. |
||
| 1472 | * |
||
| 1473 | * @param string $callback The callback function. |
||
| 1474 | * @param string $str UTF-8 string to run callback on. |
||
| 1475 | 17 | * |
|
| 1476 | * @return array The outcome of callback. |
||
| 1477 | */ |
||
| 1478 | 17 | ||
| 1479 | public static function chr_map($callback, $str) |
||
| 1485 | |||
| 1486 | 17 | /** |
|
| 1487 | 17 | * Generates an array of byte length of each character of a Unicode string. |
|
| 1488 | 17 | * |
|
| 1489 | 17 | * 1 byte => U+0000 - U+007F |
|
| 1490 | 17 | * 2 byte => U+0080 - U+07FF |
|
| 1491 | 16 | * 3 byte => U+0800 - U+FFFF |
|
| 1492 | 16 | * 4 byte => U+10000 - U+10FFFF |
|
| 1493 | 17 | * |
|
| 1494 | * @param string $str The original Unicode string. |
||
| 1495 | * |
||
| 1496 | * @return array An array of byte lengths of each character. |
||
| 1497 | */ |
||
| 1498 | 17 | public static function chr_size_list($str) |
|
| 1506 | 1 | ||
| 1507 | 1 | /** |
|
| 1508 | 1 | * Get a decimal code representation of a specific character. |
|
| 1509 | 1 | * |
|
| 1510 | 1 | * @param string $chr The input character |
|
| 1511 | * |
||
| 1512 | 1 | * @return int |
|
| 1513 | */ |
||
| 1514 | 1 | public static function chr_to_decimal($chr) |
|
| 1546 | |||
| 1547 | /** |
||
| 1548 | 5 | * Get hexadecimal code point (U+xxxx) of a UTF-8 encoded character. |
|
| 1549 | * |
||
| 1550 | * @param string $chr The input character |
||
| 1551 | 5 | * @param string $pfix |
|
| 1552 | * |
||
| 1553 | * @return string The code point encoded as U+xxxx |
||
| 1554 | */ |
||
| 1555 | 5 | public static function chr_to_hex($chr, $pfix = 'U+') |
|
| 1559 | |||
| 1560 | /** |
||
| 1561 | * Splits a string into smaller chunks and multiple lines, using the specified |
||
| 1562 | * line ending character. |
||
| 1563 | * |
||
| 1564 | * @param string $body The original string to be split. |
||
| 1565 | * @param int $chunklen The maximum character length of a chunk. |
||
| 1566 | * @param string $end The character(s) to be inserted at the end of each chunk. |
||
| 1567 | * |
||
| 1568 | * @return string The chunked string |
||
| 1569 | */ |
||
| 1570 | public static function chunk_split($body, $chunklen = 76, $end = "\r\n") |
||
| 1574 | 1 | ||
| 1575 | /** |
||
| 1576 | * accepts a string and removes all non-UTF-8 characters from it. |
||
| 1577 | * |
||
| 1578 | * @param string $str The string to be sanitized. |
||
| 1579 | * @param bool $remove_bom |
||
| 1580 | * @param bool $normalize_whitespace |
||
| 1581 | * @param bool $normalize_msword e.g.: "…" => "..." |
||
| 1582 | * @param bool $keep_non_breaking_space set true, to keep non-breaking-spaces |
||
| 1583 | * |
||
| 1584 | * @return string Clean UTF-8 encoded string |
||
| 1585 | */ |
||
| 1586 | 7 | public static function clean($str, $remove_bom = false, $normalize_whitespace = false, $normalize_msword = false, $keep_non_breaking_space = false) |
|
| 1622 | |||
| 1623 | 2 | /** |
|
| 1624 | * Clean-up a and show only printable UTF-8 chars at the end. |
||
| 1625 | * |
||
| 1626 | * @param string|false $str |
||
| 1627 | * |
||
| 1628 | * @return string |
||
| 1629 | */ |
||
| 1630 | public static function cleanup($str) |
||
| 1653 | |||
| 1654 | 10 | /** |
|
| 1655 | 1 | * Accepts a string and returns an array of Unicode code points. |
|
| 1656 | 1 | * |
|
| 1657 | 1 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
|
| 1658 | * @param bool $u_style If True, will return code points in U+xxxx format, |
||
| 1659 | 10 | * default, code points will be returned as integers. |
|
| 1660 | * |
||
| 1661 | 10 | * @return array The array of code points |
|
| 1662 | */ |
||
| 1663 | 10 | public static function codepoints($arg, $u_style = false) |
|
| 1689 | 19 | ||
| 1690 | /** |
||
| 1691 | 19 | * Returns count of characters used in a string. |
|
| 1692 | 5 | * |
|
| 1693 | * @param string $str The input string. |
||
| 1694 | * |
||
| 1695 | * @return array An associative array of Character as keys and |
||
| 1696 | 17 | * their count as values. |
|
| 1697 | */ |
||
| 1698 | 17 | public static function count_chars($str) // there is no $mode parameters |
|
| 1706 | |||
| 1707 | /** |
||
| 1708 | * Get a UTF-8 character from its decimal code representation. |
||
| 1709 | * |
||
| 1710 | 1 | * @param int $code Code. |
|
| 1711 | * |
||
| 1712 | 1 | * @return string |
|
| 1713 | */ |
||
| 1714 | 1 | public static function decimal_to_chr($code) |
|
| 1724 | 1 | ||
| 1725 | 1 | /** |
|
| 1726 | * Encode to UTF8 or LATIN1. |
||
| 1727 | 1 | * |
|
| 1728 | 1 | * INFO: The different to "UTF8::utf8_encode()" is that this function, try to fix also broken / double encoding, |
|
| 1729 | 1 | * so you can call this function also on a UTF-8 String and you don't mess the string. |
|
| 1730 | * |
||
| 1731 | 1 | * @param string $encodingLabel ISO-8859-1 || UTF-8 |
|
| 1732 | * @param string $str |
||
| 1733 | * |
||
| 1734 | * @return false|string Will return false on error. |
||
| 1735 | */ |
||
| 1736 | public static function encode($encodingLabel, $str) |
||
| 1750 | |||
| 1751 | /** |
||
| 1752 | 8 | * Reads entire file into a string. |
|
| 1753 | 1 | * |
|
| 1754 | 1 | * WARNING: do not use UTF-8 Option fir binary-files (e.g.: images) !!! |
|
| 1755 | 1 | * |
|
| 1756 | * @link http://php.net/manual/en/function.file-get-contents.php |
||
| 1757 | 8 | * |
|
| 1758 | * @param string $filename <p> |
||
| 1759 | * Name of the file to read. |
||
| 1760 | * </p> |
||
| 1761 | * @param int $flags [optional] <p> |
||
| 1762 | * Prior to PHP 6, this parameter is called |
||
| 1763 | * use_include_path and is a bool. |
||
| 1764 | * As of PHP 5 the FILE_USE_INCLUDE_PATH can be used |
||
| 1765 | * to trigger include path |
||
| 1766 | * search. |
||
| 1767 | * </p> |
||
| 1768 | * <p> |
||
| 1769 | * The value of flags can be any combination of |
||
| 1770 | * the following flags (with some restrictions), joined with the |
||
| 1771 | * binary OR (|) |
||
| 1772 | * operator. |
||
| 1773 | * </p> |
||
| 1774 | * <p> |
||
| 1775 | * <table> |
||
| 1776 | * Available flags |
||
| 1777 | * <tr valign="top"> |
||
| 1778 | * <td>Flag</td> |
||
| 1779 | * <td>Description</td> |
||
| 1780 | * </tr> |
||
| 1781 | * <tr valign="top"> |
||
| 1782 | * <td> |
||
| 1783 | * FILE_USE_INCLUDE_PATH |
||
| 1784 | * </td> |
||
| 1785 | * <td> |
||
| 1786 | * Search for filename in the include directory. |
||
| 1787 | * See include_path for more |
||
| 1788 | * information. |
||
| 1789 | * </td> |
||
| 1790 | * </tr> |
||
| 1791 | * <tr valign="top"> |
||
| 1792 | * <td> |
||
| 1793 | * FILE_TEXT |
||
| 1794 | * </td> |
||
| 1795 | * <td> |
||
| 1796 | * As of PHP 6, the default encoding of the read |
||
| 1797 | * data is UTF-8. You can specify a different encoding by creating a |
||
| 1798 | * custom context or by changing the default using |
||
| 1799 | * stream_default_encoding. This flag cannot be |
||
| 1800 | * used with FILE_BINARY. |
||
| 1801 | * </td> |
||
| 1802 | * </tr> |
||
| 1803 | * <tr valign="top"> |
||
| 1804 | * <td> |
||
| 1805 | * FILE_BINARY |
||
| 1806 | * </td> |
||
| 1807 | * <td> |
||
| 1808 | * With this flag, the file is read in binary mode. This is the default |
||
| 1809 | * setting and cannot be used with FILE_TEXT. |
||
| 1810 | * </td> |
||
| 1811 | * </tr> |
||
| 1812 | * </table> |
||
| 1813 | * </p> |
||
| 1814 | * @param resource $context [optional] <p> |
||
| 1815 | * A valid context resource created with |
||
| 1816 | * stream_context_create. If you don't need to use a |
||
| 1817 | * custom context, you can skip this parameter by &null;. |
||
| 1818 | * </p> |
||
| 1819 | * @param int $offset [optional] <p> |
||
| 1820 | * The offset where the reading starts. |
||
| 1821 | * </p> |
||
| 1822 | * @param int $maxlen [optional] <p> |
||
| 1823 | * Maximum length of data read. The default is to read until end |
||
| 1824 | * of file is reached. |
||
| 1825 | * </p> |
||
| 1826 | * @param int $timeout |
||
| 1827 | * |
||
| 1828 | * @param boolean $convertToUtf8 WARNING: maybe you can't use this option for images or pdf, because they used non |
||
| 1829 | * default utf-8 chars |
||
| 1830 | 14 | * |
|
| 1831 | * @return string The function returns the read data or false on failure. |
||
| 1832 | 14 | */ |
|
| 1833 | public static function file_get_contents($filename, $flags = null, $context = null, $offset = null, $maxlen = null, $timeout = 10, $convertToUtf8 = true) |
||
| 1880 | |||
| 1881 | /** |
||
| 1882 | * Checks if a file starts with BOM character. |
||
| 1883 | * |
||
| 1884 | * @param string $file_path Path to a valid file. |
||
| 1885 | * |
||
| 1886 | * @return bool True if the file has BOM at the start, False otherwise. |
||
| 1887 | */ |
||
| 1888 | public static function file_has_bom($file_path) |
||
| 1892 | 20 | ||
| 1893 | 2 | /** |
|
| 1894 | * Normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
||
| 1895 | 2 | * |
|
| 1896 | 2 | * @param mixed $var |
|
| 1897 | * @param int $normalization_form |
||
| 1898 | 2 | * @param string $leading_combining |
|
| 1899 | * |
||
| 1900 | * @return mixed |
||
| 1901 | 20 | */ |
|
| 1902 | public static function filter($var, $normalization_form = 4, $leading_combining = '◌') |
||
| 1945 | 1 | ||
| 1946 | 6 | /** |
|
| 1947 | 6 | * "filter_input()"-wrapper with normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
|
| 1948 | 6 | * |
|
| 1949 | * @param int $type |
||
| 1950 | * @param string $var |
||
| 1951 | 7 | * @param int $filter |
|
| 1952 | 6 | * @param mixed $option |
|
| 1953 | 6 | * |
|
| 1954 | 6 | * @return mixed |
|
| 1955 | */ |
||
| 1956 | View Code Duplication | public static function filter_input($type, $var, $filter = FILTER_DEFAULT, $option = null) |
|
| 1966 | |||
| 1967 | /** |
||
| 1968 | 2 | * "filter_input_array()"-wrapper with normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
|
| 1969 | 18 | * |
|
| 1970 | * @param int $type |
||
| 1971 | 20 | * @param mixed $definition |
|
| 1972 | * @param bool $add_empty |
||
| 1973 | 20 | * |
|
| 1974 | * @return mixed |
||
| 1975 | */ |
||
| 1976 | 20 | View Code Duplication | public static function filter_input_array($type, $definition = null, $add_empty = true) |
| 1986 | 20 | ||
| 1987 | 20 | /** |
|
| 1988 | 2 | * "filter_var()"-wrapper with normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
|
| 1989 | 20 | * |
|
| 1990 | * @param mixed $var |
||
| 1991 | 20 | * @param int $filter |
|
| 1992 | * @param mixed $option |
||
| 1993 | 20 | * |
|
| 1994 | * @return mixed |
||
| 1995 | */ |
||
| 1996 | View Code Duplication | public static function filter_var($var, $filter = FILTER_DEFAULT, $option = null) |
|
| 2006 | |||
| 2007 | /** |
||
| 2008 | * "filter_var_array()"-wrapper with normalizes to UTF-8 NFC, converting from CP-1252 when needed. |
||
| 2009 | * |
||
| 2010 | * @param array $data |
||
| 2011 | * @param mixed $definition |
||
| 2012 | * @param bool $add_empty |
||
| 2013 | * |
||
| 2014 | * @return mixed |
||
| 2015 | */ |
||
| 2016 | View Code Duplication | public static function filter_var_array($data, $definition = null, $add_empty = true) |
|
| 2026 | |||
| 2027 | /** |
||
| 2028 | * Checks if the number of Unicode characters in a string are not |
||
| 2029 | * more than the specified integer. |
||
| 2030 | * |
||
| 2031 | * @param string $str The original string to be checked. |
||
| 2032 | * @param int $box_size The size in number of chars to be checked against string. |
||
| 2033 | * |
||
| 2034 | * @return bool true if string is less than or equal to $box_size, false otherwise. |
||
| 2035 | */ |
||
| 2036 | public static function fits_inside($str, $box_size) |
||
| 2040 | |||
| 2041 | /** |
||
| 2042 | * Fixing a broken UTF-8 string. |
||
| 2043 | * |
||
| 2044 | * @param string $str |
||
| 2045 | * |
||
| 2046 | * @return string |
||
| 2047 | */ |
||
| 2048 | public static function fix_simple_utf8($str) |
||
| 2066 | |||
| 2067 | /** |
||
| 2068 | * Fix a double (or multiple) encoded UTF8 string. |
||
| 2069 | * |
||
| 2070 | * @param array|string $str |
||
| 2071 | * |
||
| 2072 | * @return string |
||
| 2073 | */ |
||
| 2074 | public static function fix_utf8($str) |
||
| 2094 | |||
| 2095 | /** |
||
| 2096 | * Get character of a specific character. |
||
| 2097 | * |
||
| 2098 | * @param string $chr Character. |
||
| 2099 | * |
||
| 2100 | * @return string 'RTL' or 'LTR' |
||
| 2101 | */ |
||
| 2102 | public static function getCharDirection($chr) |
||
| 2194 | 2 | ||
| 2195 | /** |
||
| 2196 | * get data from "/data/*.ser" |
||
| 2197 | * |
||
| 2198 | 2 | * @param string $file |
|
| 2199 | * |
||
| 2200 | * @return bool|string|array|int false on error |
||
| 2201 | */ |
||
| 2202 | protected static function getData($file) |
||
| 2211 | |||
| 2212 | /** |
||
| 2213 | * Creates a random string of UTF-8 characters. |
||
| 2214 | * |
||
| 2215 | * @param int $len The length of string in characters. |
||
| 2216 | 2 | * |
|
| 2217 | * @return string String consisting of random characters. |
||
| 2218 | */ |
||
| 2219 | public static function hash($len = 8) |
||
| 2259 | |||
| 2260 | /** |
||
| 2261 | * Converts hexadecimal U+xxxx code point representation to Integer. |
||
| 2262 | * |
||
| 2263 | * INFO: opposite to UTF8::int_to_hex( ) |
||
| 2264 | 3 | * |
|
| 2265 | * @param string $str The hexadecimal code point representation. |
||
| 2266 | * |
||
| 2267 | 3 | * @return int The code point, or 0 on failure. |
|
| 2268 | */ |
||
| 2269 | public static function hex_to_int($str) |
||
| 2277 | |||
| 2278 | 3 | /** |
|
| 2279 | * Converts a UTF-8 string to a series of HTML numbered entities. |
||
| 2280 | * |
||
| 2281 | * e.g.: {'ی |
||
| 2282 | * |
||
| 2283 | * @param string $str The Unicode string to be encoded as numbered entities. |
||
| 2284 | * |
||
| 2285 | * @return string HTML numbered entities. |
||
| 2286 | */ |
||
| 2287 | public static function html_encode($str) |
||
| 2299 | 1 | ||
| 2300 | 1 | /** |
|
| 2301 | 1 | * UTF-8 version of html_entity_decode() |
|
| 2302 | 1 | * |
|
| 2303 | 1 | * The reason we are not using html_entity_decode() by itself is because |
|
| 2304 | 1 | * while it is not technically correct to leave out the semicolon |
|
| 2305 | 1 | * at the end of an entity most browsers will still interpret the entity |
|
| 2306 | 1 | * correctly. html_entity_decode() does not convert entities without |
|
| 2307 | 1 | * semicolons, so we are left with our own little solution here. Bummer. |
|
| 2308 | * |
||
| 2309 | 1 | * Convert all HTML entities to their applicable characters |
|
| 2310 | 1 | * |
|
| 2311 | 1 | * @link http://php.net/manual/en/function.html-entity-decode.php |
|
| 2312 | 1 | * |
|
| 2313 | 1 | * @param string $str <p> |
|
| 2314 | 1 | * The input string. |
|
| 2315 | 1 | * </p> |
|
| 2316 | 1 | * @param int $flags [optional] <p> |
|
| 2317 | 1 | * A bitmask of one or more of the following flags, which specify how to handle quotes and |
|
| 2318 | 1 | * which document type to use. The default is ENT_COMPAT | ENT_HTML401. |
|
| 2319 | 1 | * <table> |
|
| 2320 | 1 | * Available <i>flags</i> constants |
|
| 2321 | 1 | * <tr valign="top"> |
|
| 2322 | 1 | * <td>Constant Name</td> |
|
| 2323 | * <td>Description</td> |
||
| 2324 | 1 | * </tr> |
|
| 2325 | 1 | * <tr valign="top"> |
|
| 2326 | 1 | * <td><b>ENT_COMPAT</b></td> |
|
| 2327 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 2328 | 1 | * </tr> |
|
| 2329 | * <tr valign="top"> |
||
| 2330 | * <td><b>ENT_QUOTES</b></td> |
||
| 2331 | * <td>Will convert both double and single quotes.</td> |
||
| 2332 | 1 | * </tr> |
|
| 2333 | * <tr valign="top"> |
||
| 2334 | 1 | * <td><b>ENT_NOQUOTES</b></td> |
|
| 2335 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 2336 | * </tr> |
||
| 2337 | * <tr valign="top"> |
||
| 2338 | * <td><b>ENT_HTML401</b></td> |
||
| 2339 | * <td> |
||
| 2340 | * Handle code as HTML 4.01. |
||
| 2341 | * </td> |
||
| 2342 | * </tr> |
||
| 2343 | * <tr valign="top"> |
||
| 2344 | * <td><b>ENT_XML1</b></td> |
||
| 2345 | 2 | * <td> |
|
| 2346 | * Handle code as XML 1. |
||
| 2347 | 2 | * </td> |
|
| 2348 | * </tr> |
||
| 2349 | 2 | * <tr valign="top"> |
|
| 2350 | * <td><b>ENT_XHTML</b></td> |
||
| 2351 | 2 | * <td> |
|
| 2352 | * Handle code as XHTML. |
||
| 2353 | * </td> |
||
| 2354 | * </tr> |
||
| 2355 | * <tr valign="top"> |
||
| 2356 | * <td><b>ENT_HTML5</b></td> |
||
| 2357 | * <td> |
||
| 2358 | * Handle code as HTML 5. |
||
| 2359 | * </td> |
||
| 2360 | * </tr> |
||
| 2361 | 1 | * </table> |
|
| 2362 | * </p> |
||
| 2363 | 1 | * @param string $encoding [optional] <p> |
|
| 2364 | 1 | * Encoding to use. |
|
| 2365 | * </p> |
||
| 2366 | 1 | * |
|
| 2367 | 1 | * @return string the decoded string. |
|
| 2368 | 1 | */ |
|
| 2369 | 1 | public static function html_entity_decode($str, $flags = null, $encoding = 'UTF-8') |
|
| 2405 | |||
| 2406 | 1 | /** |
|
| 2407 | * Callback function for preg_replace_callback use. |
||
| 2408 | * |
||
| 2409 | * @param array $matches PREG matches |
||
| 2410 | * |
||
| 2411 | * @return string |
||
| 2412 | */ |
||
| 2413 | protected static function entityCallback($matches) |
||
| 2425 | 5 | ||
| 2426 | /** |
||
| 2427 | * Convert all applicable characters to HTML entities: UTF-8 version of htmlentities() |
||
| 2428 | 5 | * |
|
| 2429 | * @link http://php.net/manual/en/function.htmlentities.php |
||
| 2430 | * |
||
| 2431 | * @param string $str <p> |
||
| 2432 | * The input string. |
||
| 2433 | * </p> |
||
| 2434 | * @param int $flags [optional] <p> |
||
| 2435 | 5 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
|
| 2436 | * invalid code unit sequences and the used document type. The default is |
||
| 2437 | 5 | * ENT_COMPAT | ENT_HTML401. |
|
| 2438 | * <table> |
||
| 2439 | * Available <i>flags</i> constants |
||
| 2440 | * <tr valign="top"> |
||
| 2441 | * <td>Constant Name</td> |
||
| 2442 | * <td>Description</td> |
||
| 2443 | * </tr> |
||
| 2444 | * <tr valign="top"> |
||
| 2445 | * <td><b>ENT_COMPAT</b></td> |
||
| 2446 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 2447 | * </tr> |
||
| 2448 | * <tr valign="top"> |
||
| 2449 | * <td><b>ENT_QUOTES</b></td> |
||
| 2450 | * <td>Will convert both double and single quotes.</td> |
||
| 2451 | * </tr> |
||
| 2452 | * <tr valign="top"> |
||
| 2453 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 2454 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 2455 | * </tr> |
||
| 2456 | * <tr valign="top"> |
||
| 2457 | * <td><b>ENT_IGNORE</b></td> |
||
| 2458 | * <td> |
||
| 2459 | * Silently discard invalid code unit sequences instead of returning |
||
| 2460 | * an empty string. Using this flag is discouraged as it |
||
| 2461 | * may have security implications. |
||
| 2462 | * </td> |
||
| 2463 | * </tr> |
||
| 2464 | * <tr valign="top"> |
||
| 2465 | * <td><b>ENT_SUBSTITUTE</b></td> |
||
| 2466 | * <td> |
||
| 2467 | * Replace invalid code unit sequences with a Unicode Replacement Character |
||
| 2468 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
| 2469 | * </td> |
||
| 2470 | * </tr> |
||
| 2471 | * <tr valign="top"> |
||
| 2472 | * <td><b>ENT_DISALLOWED</b></td> |
||
| 2473 | * <td> |
||
| 2474 | * Replace invalid code points for the given document type with a |
||
| 2475 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
| 2476 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
| 2477 | * instance, to ensure the well-formedness of XML documents with |
||
| 2478 | * embedded external content. |
||
| 2479 | * </td> |
||
| 2480 | * </tr> |
||
| 2481 | * <tr valign="top"> |
||
| 2482 | * <td><b>ENT_HTML401</b></td> |
||
| 2483 | * <td> |
||
| 2484 | * Handle code as HTML 4.01. |
||
| 2485 | * </td> |
||
| 2486 | * </tr> |
||
| 2487 | * <tr valign="top"> |
||
| 2488 | 1 | * <td><b>ENT_XML1</b></td> |
|
| 2489 | * <td> |
||
| 2490 | 1 | * Handle code as XML 1. |
|
| 2491 | * </td> |
||
| 2492 | 1 | * </tr> |
|
| 2493 | * <tr valign="top"> |
||
| 2494 | * <td><b>ENT_XHTML</b></td> |
||
| 2495 | * <td> |
||
| 2496 | * Handle code as XHTML. |
||
| 2497 | * </td> |
||
| 2498 | * </tr> |
||
| 2499 | * <tr valign="top"> |
||
| 2500 | * <td><b>ENT_HTML5</b></td> |
||
| 2501 | * <td> |
||
| 2502 | * Handle code as HTML 5. |
||
| 2503 | * </td> |
||
| 2504 | * </tr> |
||
| 2505 | * </table> |
||
| 2506 | * </p> |
||
| 2507 | * @param string $encoding [optional] <p> |
||
| 2508 | * Like <b>htmlspecialchars</b>, |
||
| 2509 | * <b>htmlentities</b> takes an optional third argument |
||
| 2510 | * <i>encoding</i> which defines encoding used in |
||
| 2511 | * conversion. |
||
| 2512 | * Although this argument is technically optional, you are highly |
||
| 2513 | * encouraged to specify the correct value for your code. |
||
| 2514 | * </p> |
||
| 2515 | * @param bool $double_encode [optional] <p> |
||
| 2516 | * When <i>double_encode</i> is turned off PHP will not |
||
| 2517 | * encode existing html entities. The default is to convert everything. |
||
| 2518 | * </p> |
||
| 2519 | * |
||
| 2520 | * |
||
| 2521 | * @return string the encoded string. |
||
| 2522 | * </p> |
||
| 2523 | 1 | * <p> |
|
| 2524 | * If the input <i>string</i> contains an invalid code unit |
||
| 2525 | 1 | * sequence within the given <i>encoding</i> an empty string |
|
| 2526 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
| 2527 | 1 | * <b>ENT_SUBSTITUTE</b> flags are set. |
|
| 2528 | */ |
||
| 2529 | public static function htmlentities($str, $flags = ENT_COMPAT, $encoding = 'UTF-8', $double_encode = true) |
||
| 2533 | |||
| 2534 | /** |
||
| 2535 | * Convert special characters to HTML entities: UTF-8 version of htmlspecialchars() |
||
| 2536 | * |
||
| 2537 | * @link http://php.net/manual/en/function.htmlspecialchars.php |
||
| 2538 | * |
||
| 2539 | 1 | * @param string $str <p> |
|
| 2540 | * The string being converted. |
||
| 2541 | 1 | * </p> |
|
| 2542 | 1 | * @param int $flags [optional] <p> |
|
| 2543 | 1 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
|
| 2544 | 1 | * invalid code unit sequences and the used document type. The default is |
|
| 2545 | * ENT_COMPAT | ENT_HTML401. |
||
| 2546 | * <table> |
||
| 2547 | 1 | * Available <i>flags</i> constants |
|
| 2548 | * <tr valign="top"> |
||
| 2549 | * <td>Constant Name</td> |
||
| 2550 | * <td>Description</td> |
||
| 2551 | * </tr> |
||
| 2552 | * <tr valign="top"> |
||
| 2553 | * <td><b>ENT_COMPAT</b></td> |
||
| 2554 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 2555 | * </tr> |
||
| 2556 | * <tr valign="top"> |
||
| 2557 | * <td><b>ENT_QUOTES</b></td> |
||
| 2558 | * <td>Will convert both double and single quotes.</td> |
||
| 2559 | 6 | * </tr> |
|
| 2560 | * <tr valign="top"> |
||
| 2561 | 6 | * <td><b>ENT_NOQUOTES</b></td> |
|
| 2562 | 6 | * <td>Will leave both double and single quotes unconverted.</td> |
|
| 2563 | 1 | * </tr> |
|
| 2564 | * <tr valign="top"> |
||
| 2565 | * <td><b>ENT_IGNORE</b></td> |
||
| 2566 | 1 | * <td> |
|
| 2567 | 1 | * Silently discard invalid code unit sequences instead of returning |
|
| 2568 | 6 | * an empty string. Using this flag is discouraged as it |
|
| 2569 | 1 | * may have security implications. |
|
| 2570 | 1 | * </td> |
|
| 2571 | 1 | * </tr> |
|
| 2572 | 1 | * <tr valign="top"> |
|
| 2573 | 6 | * <td><b>ENT_SUBSTITUTE</b></td> |
|
| 2574 | 6 | * <td> |
|
| 2575 | * Replace invalid code unit sequences with a Unicode Replacement Character |
||
| 2576 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
| 2577 | * </td> |
||
| 2578 | 6 | * </tr> |
|
| 2579 | 6 | * <tr valign="top"> |
|
| 2580 | 1 | * <td><b>ENT_DISALLOWED</b></td> |
|
| 2581 | 1 | * <td> |
|
| 2582 | 6 | * Replace invalid code points for the given document type with a |
|
| 2583 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
| 2584 | 6 | * (otherwise) instead of leaving them as is. This may be useful, for |
|
| 2585 | 4 | * instance, to ensure the well-formedness of XML documents with |
|
| 2586 | 4 | * embedded external content. |
|
| 2587 | 4 | * </td> |
|
| 2588 | * </tr> |
||
| 2589 | * <tr valign="top"> |
||
| 2590 | * <td><b>ENT_HTML401</b></td> |
||
| 2591 | 6 | * <td> |
|
| 2592 | * Handle code as HTML 4.01. |
||
| 2593 | * </td> |
||
| 2594 | * </tr> |
||
| 2595 | * <tr valign="top"> |
||
| 2596 | 6 | * <td><b>ENT_XML1</b></td> |
|
| 2597 | 6 | * <td> |
|
| 2598 | 6 | * Handle code as XML 1. |
|
| 2599 | * </td> |
||
| 2600 | 6 | * </tr> |
|
| 2601 | * <tr valign="top"> |
||
| 2602 | * <td><b>ENT_XHTML</b></td> |
||
| 2603 | * <td> |
||
| 2604 | * Handle code as XHTML. |
||
| 2605 | * </td> |
||
| 2606 | * </tr> |
||
| 2607 | * <tr valign="top"> |
||
| 2608 | * <td><b>ENT_HTML5</b></td> |
||
| 2609 | * <td> |
||
| 2610 | * Handle code as HTML 5. |
||
| 2611 | * </td> |
||
| 2612 | * </tr> |
||
| 2613 | * </table> |
||
| 2614 | 11 | * </p> |
|
| 2615 | * @param string $encoding [optional] <p> |
||
| 2616 | 11 | * Defines encoding used in conversion. |
|
| 2617 | * </p> |
||
| 2618 | 11 | * <p> |
|
| 2619 | 11 | * For the purposes of this function, the encodings |
|
| 2620 | * ISO-8859-1, ISO-8859-15, |
||
| 2621 | * UTF-8, cp866, |
||
| 2622 | 1 | * cp1251, cp1252, and |
|
| 2623 | 1 | * KOI8-R are effectively equivalent, provided the |
|
| 2624 | * <i>string</i> itself is valid for the encoding, as |
||
| 2625 | * the characters affected by <b>htmlspecialchars</b> occupy |
||
| 2626 | * the same positions in all of these encodings. |
||
| 2627 | * </p> |
||
| 2628 | * @param bool $double_encode [optional] <p> |
||
| 2629 | * When <i>double_encode</i> is turned off PHP will not |
||
| 2630 | * encode existing html entities, the default is to convert everything. |
||
| 2631 | * </p> |
||
| 2632 | * |
||
| 2633 | * @return string The converted string. |
||
| 2634 | * </p> |
||
| 2635 | * <p> |
||
| 2636 | 11 | * If the input <i>string</i> contains an invalid code unit |
|
| 2637 | * sequence within the given <i>encoding</i> an empty string |
||
| 2638 | 11 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
|
| 2639 | 11 | * <b>ENT_SUBSTITUTE</b> flags are set. |
|
| 2640 | */ |
||
| 2641 | 11 | public static function htmlspecialchars($str, $flags = ENT_COMPAT, $encoding = 'UTF-8', $double_encode = true) |
|
| 2645 | 11 | ||
| 2646 | 11 | /** |
|
| 2647 | 11 | * checks whether iconv is available on the server |
|
| 2648 | 11 | * |
|
| 2649 | 11 | * @return bool True if available, False otherwise |
|
| 2650 | 11 | */ |
|
| 2651 | 11 | public static function iconv_loaded() |
|
| 2655 | 11 | ||
| 2656 | /** |
||
| 2657 | * Converts Integer to hexadecimal U+xxxx code point representation. |
||
| 2658 | * |
||
| 2659 | * @param int $int The integer to be converted to hexadecimal code point. |
||
| 2660 | * @param string $pfix |
||
| 2661 | * |
||
| 2662 | * @return string The code point, or empty string on failure. |
||
| 2663 | */ |
||
| 2664 | public static function int_to_hex($int, $pfix = 'U+') |
||
| 2676 | |||
| 2677 | 2 | /** |
|
| 2678 | * checks whether intl is available on the server |
||
| 2679 | 2 | * |
|
| 2680 | * @return bool True if available, False otherwise |
||
| 2681 | 1 | */ |
|
| 2682 | public static function intl_loaded() |
||
| 2686 | 1 | ||
| 2687 | 2 | /** |
|
| 2688 | 2 | * alias for "UTF8::is_ascii()" |
|
| 2689 | * |
||
| 2690 | * @param string $str |
||
| 2691 | * |
||
| 2692 | * @return boolean |
||
| 2693 | */ |
||
| 2694 | public static function isAscii($str) |
||
| 2698 | |||
| 2699 | /** |
||
| 2700 | * alias for "UTF8::is_base64" |
||
| 2701 | 6 | * |
|
| 2702 | * @param string $str |
||
| 2703 | 6 | * |
|
| 2704 | 6 | * @return bool |
|
| 2705 | */ |
||
| 2706 | 6 | public static function isBase64($str) |
|
| 2710 | |||
| 2711 | /** |
||
| 2712 | * alias for "UTF8::is_bom" |
||
| 2713 | 6 | * |
|
| 2714 | * @param string $utf8_chr |
||
| 2715 | 6 | * |
|
| 2716 | * @return boolean |
||
| 2717 | 6 | */ |
|
| 2718 | 1 | public static function isBom($utf8_chr) |
|
| 2722 | 6 | ||
| 2723 | /** |
||
| 2724 | * Try to check if a string is a json-string... |
||
| 2725 | * |
||
| 2726 | * @param $str |
||
| 2727 | * |
||
| 2728 | * @return bool |
||
| 2729 | * |
||
| 2730 | * @deprecated |
||
| 2731 | */ |
||
| 2732 | public static function isJson($str) |
||
| 2750 | |||
| 2751 | /** |
||
| 2752 | * alias for "UTF8::is_utf8" |
||
| 2753 | 6 | * |
|
| 2754 | * @param string $str |
||
| 2755 | 6 | * |
|
| 2756 | * @return bool |
||
| 2757 | 6 | */ |
|
| 2758 | 6 | public static function isUtf8($str) |
|
| 2762 | 5 | ||
| 2763 | /** |
||
| 2764 | 5 | * Checks if a string is 7 bit ASCII. |
|
| 2765 | 1 | * |
|
| 2766 | 1 | * @param string $str The string to check. |
|
| 2767 | 1 | * |
|
| 2768 | * @return bool <strong>true</strong> if it is ASCII<br /> |
||
| 2769 | 5 | * <strong>false</strong> otherwise |
|
| 2770 | */ |
||
| 2771 | public static function is_ascii($str) |
||
| 2775 | |||
| 2776 | /** |
||
| 2777 | * Returns true if the string is base64 encoded, false otherwise. |
||
| 2778 | * |
||
| 2779 | * @param string $str |
||
| 2780 | * |
||
| 2781 | * @return bool Whether or not $str is base64 encoded |
||
| 2782 | */ |
||
| 2783 | public static function is_base64($str) |
||
| 2797 | |||
| 2798 | /** |
||
| 2799 | * Check if the input is binary... (is look like a hack) |
||
| 2800 | * |
||
| 2801 | * @param string $input |
||
| 2802 | * |
||
| 2803 | * @return bool |
||
| 2804 | */ |
||
| 2805 | public static function is_binary($input) |
||
| 2822 | |||
| 2823 | /** |
||
| 2824 | * Check if the file is binary. |
||
| 2825 | * |
||
| 2826 | * @param string $file |
||
| 2827 | * |
||
| 2828 | * @return boolean |
||
| 2829 | */ |
||
| 2830 | public static function is_binary_file($file) |
||
| 2842 | |||
| 2843 | /** |
||
| 2844 | * Checks if the given string is exactly "UTF8 - Byte Order Mark". |
||
| 2845 | * |
||
| 2846 | * WARNING: Use "UTF8::string_has_bom()" if you will check BOM in a string. |
||
| 2847 | * |
||
| 2848 | * @param string $utf8_chr The input string. |
||
| 2849 | * |
||
| 2850 | * @return bool True if the $utf8_chr is Byte Order Mark, False otherwise. |
||
| 2851 | */ |
||
| 2852 | public static function is_bom($utf8_chr) |
||
| 2856 | |||
| 2857 | /** |
||
| 2858 | 2 | * Check if the string is UTF-16. |
|
| 2859 | * |
||
| 2860 | 2 | * @param string $str |
|
| 2861 | * |
||
| 2862 | 2 | * @return int|false false if is't not UTF16, 1 for UTF-16LE, 2 for UTF-16BE. |
|
| 2863 | 2 | */ |
|
| 2864 | 2 | View Code Duplication | public static function is_utf16($str) |
| 2911 | |||
| 2912 | /** |
||
| 2913 | * Check if the string is UTF-32. |
||
| 2914 | * |
||
| 2915 | * @param string $str |
||
| 2916 | * |
||
| 2917 | * @return int|false false if is't not UTF16, 1 for UTF-32LE, 2 for UTF-32BE. |
||
| 2918 | */ |
||
| 2919 | View Code Duplication | public static function is_utf32($str) |
|
| 2966 | 1 | ||
| 2967 | /** |
||
| 2968 | * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters. |
||
| 2969 | * |
||
| 2970 | * @see http://hsivonen.iki.fi/php-utf8/ |
||
| 2971 | * |
||
| 2972 | * @param string $str The string to be checked. |
||
| 2973 | * |
||
| 2974 | * @return bool |
||
| 2975 | */ |
||
| 2976 | public static function is_utf8($str) |
||
| 3100 | |||
| 3101 | /** |
||
| 3102 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
||
| 3103 | * Decodes a JSON string |
||
| 3104 | * |
||
| 3105 | * @link http://php.net/manual/en/function.json-decode.php |
||
| 3106 | * |
||
| 3107 | * @param string $json <p> |
||
| 3108 | * The <i>json</i> string being decoded. |
||
| 3109 | * </p> |
||
| 3110 | * <p> |
||
| 3111 | * This function only works with UTF-8 encoded strings. |
||
| 3112 | * </p> |
||
| 3113 | * <p>PHP implements a superset of |
||
| 3114 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
||
| 3115 | * only supports these values when they are nested inside an array or an object. |
||
| 3116 | 1 | * </p> |
|
| 3117 | * @param bool $assoc [optional] <p> |
||
| 3118 | 1 | * When <b>TRUE</b>, returned objects will be converted into |
|
| 3119 | * associative arrays. |
||
| 3120 | * </p> |
||
| 3121 | * @param int $depth [optional] <p> |
||
| 3122 | * User specified recursion depth. |
||
| 3123 | * </p> |
||
| 3124 | * @param int $options [optional] <p> |
||
| 3125 | * Bitmask of JSON decode options. Currently only |
||
| 3126 | * <b>JSON_BIGINT_AS_STRING</b> |
||
| 3127 | * is supported (default is to cast large integers as floats) |
||
| 3128 | * </p> |
||
| 3129 | * |
||
| 3130 | * @return mixed the value encoded in <i>json</i> in appropriate |
||
| 3131 | * PHP type. Values true, false and |
||
| 3132 | * null (case-insensitive) are returned as <b>TRUE</b>, <b>FALSE</b> |
||
| 3133 | * and <b>NULL</b> respectively. <b>NULL</b> is returned if the |
||
| 3134 | * <i>json</i> cannot be decoded or if the encoded |
||
| 3135 | * data is deeper than the recursion limit. |
||
| 3136 | */ |
||
| 3137 | public static function json_decode($json, $assoc = false, $depth = 512, $options = 0) |
||
| 3149 | |||
| 3150 | /** |
||
| 3151 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
||
| 3152 | * Returns the JSON representation of a value |
||
| 3153 | * |
||
| 3154 | * @link http://php.net/manual/en/function.json-encode.php |
||
| 3155 | * |
||
| 3156 | * @param mixed $value <p> |
||
| 3157 | * The <i>value</i> being encoded. Can be any type except |
||
| 3158 | * a resource. |
||
| 3159 | * </p> |
||
| 3160 | * <p> |
||
| 3161 | * All string data must be UTF-8 encoded. |
||
| 3162 | * </p> |
||
| 3163 | * <p>PHP implements a superset of |
||
| 3164 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
||
| 3165 | 4 | * only supports these values when they are nested inside an array or an object. |
|
| 3166 | * </p> |
||
| 3167 | 4 | * @param int $options [optional] <p> |
|
| 3168 | * Bitmask consisting of <b>JSON_HEX_QUOT</b>, |
||
| 3169 | * <b>JSON_HEX_TAG</b>, |
||
| 3170 | * <b>JSON_HEX_AMP</b>, |
||
| 3171 | 4 | * <b>JSON_HEX_APOS</b>, |
|
| 3172 | 4 | * <b>JSON_NUMERIC_CHECK</b>, |
|
| 3173 | 4 | * <b>JSON_PRETTY_PRINT</b>, |
|
| 3174 | * <b>JSON_UNESCAPED_SLASHES</b>, |
||
| 3175 | 4 | * <b>JSON_FORCE_OBJECT</b>, |
|
| 3176 | 4 | * <b>JSON_UNESCAPED_UNICODE</b>. The behaviour of these |
|
| 3177 | 4 | * constants is described on |
|
| 3178 | 4 | * the JSON constants page. |
|
| 3179 | * </p> |
||
| 3180 | 4 | * @param int $depth [optional] <p> |
|
| 3181 | * Set the maximum depth. Must be greater than zero. |
||
| 3182 | * </p> |
||
| 3183 | * |
||
| 3184 | 4 | * @return string a JSON encoded string on success or <b>FALSE</b> on failure. |
|
| 3185 | */ |
||
| 3186 | 4 | public static function json_encode($value, $options = 0, $depth = 512) |
|
| 3198 | 4 | ||
| 3199 | /** |
||
| 3200 | 4 | * Makes string's first char lowercase. |
|
| 3201 | 4 | * |
|
| 3202 | 4 | * @param string $str The input string |
|
| 3203 | 4 | * |
|
| 3204 | * @return string The resulting string |
||
| 3205 | 4 | */ |
|
| 3206 | 3 | public static function lcfirst($str) |
|
| 3210 | |||
| 3211 | 3 | /** |
|
| 3212 | * Strip whitespace or other characters from beginning of a UTF-8 string. |
||
| 3213 | * |
||
| 3214 | * WARNING: This is much slower then "ltrim()" !!!! |
||
| 3215 | 3 | * |
|
| 3216 | 3 | * @param string $str The string to be trimmed |
|
| 3217 | * @param string $chars Optional characters to be stripped |
||
| 3218 | 4 | * |
|
| 3219 | * @return string The string with unwanted characters stripped from the left |
||
| 3220 | */ |
||
| 3221 | View Code Duplication | public static function ltrim($str = '', $chars = INF) |
|
| 3233 | |||
| 3234 | /** |
||
| 3235 | * Returns the UTF-8 character with the maximum code point in the given data. |
||
| 3236 | * |
||
| 3237 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
||
| 3238 | * |
||
| 3239 | * @return string The character with the highest code point than others. |
||
| 3240 | */ |
||
| 3241 | View Code Duplication | public static function max($arg) |
|
| 3249 | 2 | ||
| 3250 | /** |
||
| 3251 | * Calculates and returns the maximum number of bytes taken by any |
||
| 3252 | * UTF-8 encoded character in the given string. |
||
| 3253 | 10 | * |
|
| 3254 | 10 | * @param string $str The original Unicode string. |
|
| 3255 | * |
||
| 3256 | * @return int An array of byte lengths of each character. |
||
| 3257 | */ |
||
| 3258 | 10 | public static function max_chr_width($str) |
|
| 3267 | 1 | ||
| 3268 | 1 | /** |
|
| 3269 | * checks whether mbstring is available on the server |
||
| 3270 | 10 | * |
|
| 3271 | * @return bool True if available, False otherwise |
||
| 3272 | */ |
||
| 3273 | 10 | public static function mbstring_loaded() |
|
| 3283 | |||
| 3284 | /** |
||
| 3285 | * Returns the UTF-8 character with the minimum code point in the given data. |
||
| 3286 | * |
||
| 3287 | * @param mixed $arg A UTF-8 encoded string or an array of such strings. |
||
| 3288 | * |
||
| 3289 | * @return string The character with the lowest code point than others. |
||
| 3290 | */ |
||
| 3291 | View Code Duplication | public static function min($arg) |
|
| 3299 | |||
| 3300 | /** |
||
| 3301 | * Normalize the encoding-name input. |
||
| 3302 | * |
||
| 3303 | * @param string $encodingLabel e.g.: ISO, UTF8, WINDOWS-1251 etc. |
||
| 3304 | * |
||
| 3305 | * @return string e.g.: ISO-8859-1, UTF-8, ISO-8859-5 etc. |
||
| 3306 | 8 | */ |
|
| 3307 | public static function normalizeEncoding($encodingLabel) |
||
| 3335 | |||
| 3336 | /** |
||
| 3337 | * Normalize MS Word special characters. |
||
| 3338 | * |
||
| 3339 | * @param string $str The string to be normalized. |
||
| 3340 | * |
||
| 3341 | * @return string |
||
| 3342 | */ |
||
| 3343 | public static function normalize_msword($str) |
||
| 3355 | |||
| 3356 | /** |
||
| 3357 | 1 | * Normalize the whitespace. |
|
| 3358 | * |
||
| 3359 | 1 | * @param string $str The string to be normalized. |
|
| 3360 | * @param bool $keepNonBreakingSpace Set to true, to keep non-breaking-spaces. |
||
| 3361 | * @param bool $keepBidiUnicodeControls Set to true, to keep non-printable (for the web) bidirectional text chars. |
||
| 3362 | * |
||
| 3363 | 1 | * @return string |
|
| 3364 | */ |
||
| 3365 | public static function normalize_whitespace($str, $keepNonBreakingSpace = false, $keepBidiUnicodeControls = false) |
||
| 3394 | |||
| 3395 | /** |
||
| 3396 | * Format a number with grouped thousands. |
||
| 3397 | * |
||
| 3398 | * @param float $number |
||
| 3399 | * @param int $decimals |
||
| 3400 | * @param string $dec_point |
||
| 3401 | 3 | * @param string $thousands_sep |
|
| 3402 | * |
||
| 3403 | * @return string |
||
| 3404 | */ |
||
| 3405 | public static function number_format($number, $decimals = 0, $dec_point = '.', $thousands_sep = ',') |
||
| 3425 | |||
| 3426 | /** |
||
| 3427 | * Calculates Unicode code point of the given UTF-8 encoded character. |
||
| 3428 | * |
||
| 3429 | * @param string $s The character of which to calculate code point. |
||
| 3430 | * |
||
| 3431 | * @return int Unicode code point of the given character,<br /> |
||
| 3432 | * 0 on invalid UTF-8 byte sequence. |
||
| 3433 | */ |
||
| 3434 | public static function ord($s) |
||
| 3457 | |||
| 3458 | /** |
||
| 3459 | * Parses the string into variables. |
||
| 3460 | * |
||
| 3461 | 1 | * WARNING: This differs from parse_str() by returning the results |
|
| 3462 | * instead of placing them in the local scope! |
||
| 3463 | 1 | * |
|
| 3464 | * @link http://php.net/manual/en/function.parse-str.php |
||
| 3465 | 1 | * |
|
| 3466 | * @param string $str <p> |
||
| 3467 | * The input string. |
||
| 3468 | * </p> |
||
| 3469 | * @param array $result <p> |
||
| 3470 | 1 | * If the second parameter arr is present, |
|
| 3471 | 1 | * variables are stored in this variable as array elements instead. |
|
| 3472 | * </p> |
||
| 3473 | 1 | * |
|
| 3474 | 1 | * @return void |
|
| 3475 | 1 | */ |
|
| 3476 | public static function parse_str($str, &$result) |
||
| 3485 | |||
| 3486 | /** |
||
| 3487 | * checks if \u modifier is available that enables Unicode support in PCRE. |
||
| 3488 | * |
||
| 3489 | 1 | * @return bool True if support is available, false otherwise |
|
| 3490 | */ |
||
| 3491 | 1 | public static function pcre_utf8_support() |
|
| 3496 | 1 | ||
| 3497 | /** |
||
| 3498 | * Create an array containing a range of UTF-8 characters. |
||
| 3499 | * |
||
| 3500 | 1 | * @param mixed $var1 Numeric or hexadecimal code points, or a UTF-8 character to start from. |
|
| 3501 | * @param mixed $var2 Numeric or hexadecimal code points, or a UTF-8 character to end at. |
||
| 3502 | * |
||
| 3503 | * @return array |
||
| 3504 | */ |
||
| 3505 | public static function range($var1, $var2) |
||
| 3543 | |||
| 3544 | /** |
||
| 3545 | * Remove the BOM from UTF-8 / UTF-16 / UTF-32 strings. |
||
| 3546 | * |
||
| 3547 | * @param string $str |
||
| 3548 | * |
||
| 3549 | * @return string |
||
| 3550 | */ |
||
| 3551 | public static function removeBOM($str = '') |
||
| 3591 | |||
| 3592 | /** |
||
| 3593 | * Removes duplicate occurrences of a string in another string. |
||
| 3594 | * |
||
| 3595 | * @param string $str The base string |
||
| 3596 | * @param string|array $what String to search for in the base string |
||
| 3597 | * |
||
| 3598 | * @return string The result string with removed duplicates |
||
| 3599 | */ |
||
| 3600 | public static function remove_duplicates($str, $what = ' ') |
||
| 3614 | |||
| 3615 | /** |
||
| 3616 | 1 | * Remove Invisible Characters |
|
| 3617 | * |
||
| 3618 | * This prevents sandwiching null characters |
||
| 3619 | * between ascii characters, like Java\0script. |
||
| 3620 | * |
||
| 3621 | * copy&past from https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Common.php |
||
| 3622 | 1 | * |
|
| 3623 | * @param string $str |
||
| 3624 | * @param bool $url_encoded |
||
| 3625 | * |
||
| 3626 | 1 | * @return string |
|
| 3627 | 1 | */ |
|
| 3628 | 1 | public static function remove_invisible_characters($str, $url_encoded = true) |
|
| 3648 | 1 | ||
| 3649 | /** |
||
| 3650 | 1 | * replace diamond question mark (�) |
|
| 3651 | * |
||
| 3652 | * @param string $str |
||
| 3653 | 6 | * @param string $unknown |
|
| 3654 | 6 | * |
|
| 3655 | * @return string |
||
| 3656 | 6 | */ |
|
| 3657 | 4 | public static function replace_diamond_question_mark($str, $unknown = '?') |
|
| 3671 | |||
| 3672 | /** |
||
| 3673 | * Strip whitespace or other characters from end of a UTF-8 string. |
||
| 3674 | * |
||
| 3675 | * WARNING: This is much slower then "rtrim()" !!!! |
||
| 3676 | * |
||
| 3677 | * @param string $str The string to be trimmed |
||
| 3678 | * @param string $chars Optional characters to be stripped |
||
| 3679 | * |
||
| 3680 | * @return string The string with unwanted characters stripped from the right |
||
| 3681 | */ |
||
| 3682 | View Code Duplication | public static function rtrim($str = '', $chars = INF) |
|
| 3694 | |||
| 3695 | /** |
||
| 3696 | * rxClass |
||
| 3697 | * |
||
| 3698 | * @param string $s |
||
| 3699 | * @param string $class |
||
| 3700 | * |
||
| 3701 | * @return string |
||
| 3702 | */ |
||
| 3703 | protected static function rxClass($s, $class = '') |
||
| 3739 | |||
| 3740 | 1 | /** |
|
| 3741 | 1 | * Echo native UTF8-Support libs, e.g. for debugging. |
|
| 3742 | */ |
||
| 3743 | public static function showSupport() |
||
| 3749 | 1 | ||
| 3750 | /** |
||
| 3751 | * Converts a UTF-8 character to HTML Numbered Entity like "{". |
||
| 3752 | 1 | * |
|
| 3753 | * @param string $chr The Unicode character to be encoded as numbered entity. |
||
| 3754 | * |
||
| 3755 | * @return string The HTML numbered entity. |
||
| 3756 | 1 | */ |
|
| 3757 | public static function single_chr_html_encode($chr) |
||
| 3765 | |||
| 3766 | /** |
||
| 3767 | * Convert a string to an array of Unicode characters. |
||
| 3768 | 1 | * |
|
| 3769 | * @param string $str The string to split into array. |
||
| 3770 | 1 | * @param int $length Max character length of each array element. |
|
| 3771 | 1 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string. |
|
| 3772 | 1 | * |
|
| 3773 | 1 | * @return array An array containing chunks of the string. |
|
| 3774 | 1 | */ |
|
| 3775 | public static function split($str, $length = 1, $cleanUtf8 = false) |
||
| 3844 | |||
| 3845 | /** |
||
| 3846 | * Optimized "mb_detect_encoding()"-function -> with support for UTF-16 and UTF-32. |
||
| 3847 | * |
||
| 3848 | * @param string $str |
||
| 3849 | 1 | * |
|
| 3850 | * @return false|string The detected string-encoding e.g. UTF-8 or UTF-16BE,<br /> |
||
| 3851 | 1 | * otherwise it will return false. |
|
| 3852 | */ |
||
| 3853 | 1 | public static function str_detect_encoding($str) |
|
| 3924 | |||
| 3925 | /** |
||
| 3926 | * str_ireplace |
||
| 3927 | * |
||
| 3928 | * @param string $search |
||
| 3929 | * @param string $replace |
||
| 3930 | * @param string $subject |
||
| 3931 | * @param null $count |
||
| 3932 | * |
||
| 3933 | * @return string |
||
| 3934 | */ |
||
| 3935 | public static function str_ireplace($search, $replace, $subject, &$count = null) |
||
| 3953 | |||
| 3954 | 2 | /** |
|
| 3955 | * Limit the number of characters in a string, but also after the next word. |
||
| 3956 | 2 | * |
|
| 3957 | * @param string $str |
||
| 3958 | 2 | * @param int $length |
|
| 3959 | 2 | * @param string $strAddOn |
|
| 3960 | * |
||
| 3961 | 2 | * @return string |
|
| 3962 | */ |
||
| 3963 | public static function str_limit_after_word($str, $length = 100, $strAddOn = '...') |
||
| 3992 | |||
| 3993 | /** |
||
| 3994 | * Pad a UTF-8 string to given length with another string. |
||
| 3995 | * |
||
| 3996 | * @param string $input The input string |
||
| 3997 | * @param int $pad_length The length of return string |
||
| 3998 | * @param string $pad_string String to use for padding the input string |
||
| 3999 | * @param int $pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT or STR_PAD_BOTH |
||
| 4000 | * |
||
| 4001 | * @return string Returns the padded string |
||
| 4002 | */ |
||
| 4003 | public static function str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) |
||
| 4038 | |||
| 4039 | /** |
||
| 4040 | * Repeat a string. |
||
| 4041 | * |
||
| 4042 | * @param string $input <p> |
||
| 4043 | * The string to be repeated. |
||
| 4044 | * </p> |
||
| 4045 | * @param int $multiplier <p> |
||
| 4046 | * Number of time the input string should be |
||
| 4047 | * repeated. |
||
| 4048 | * </p> |
||
| 4049 | * <p> |
||
| 4050 | * multiplier has to be greater than or equal to 0. |
||
| 4051 | * If the multiplier is set to 0, the function |
||
| 4052 | * will return an empty string. |
||
| 4053 | * </p> |
||
| 4054 | * |
||
| 4055 | * @return string the repeated string. |
||
| 4056 | */ |
||
| 4057 | public static function str_repeat($input, $multiplier) |
||
| 4063 | 8 | ||
| 4064 | 8 | /** |
|
| 4065 | * INFO: this is only a wrapper for "str_replace()" -> the original functions is already UTF-8 safe |
||
| 4066 | 8 | * |
|
| 4067 | 2 | * (PHP 4, PHP 5)<br/> |
|
| 4068 | * Replace all occurrences of the search string with the replacement string |
||
| 4069 | * |
||
| 4070 | * @link http://php.net/manual/en/function.str-replace.php |
||
| 4071 | 7 | * |
|
| 4072 | * @param mixed $search <p> |
||
| 4073 | 7 | * The value being searched for, otherwise known as the needle. |
|
| 4074 | 1 | * An array may be used to designate multiple needles. |
|
| 4075 | 1 | * </p> |
|
| 4076 | 1 | * @param mixed $replace <p> |
|
| 4077 | * The replacement value that replaces found search |
||
| 4078 | * values. An array may be used to designate multiple replacements. |
||
| 4079 | 7 | * </p> |
|
| 4080 | 1 | * @param mixed $subject <p> |
|
| 4081 | 1 | * The string or array being searched and replaced on, |
|
| 4082 | * otherwise known as the haystack. |
||
| 4083 | 7 | * </p> |
|
| 4084 | * <p> |
||
| 4085 | * If subject is an array, then the search and |
||
| 4086 | * replace is performed with every entry of |
||
| 4087 | * subject, and the return value is an array as |
||
| 4088 | * well. |
||
| 4089 | * </p> |
||
| 4090 | * @param int $count [optional] If passed, this will hold the number of matched and replaced needles. |
||
| 4091 | * |
||
| 4092 | * @return mixed This function returns a string or an array with the replaced values. |
||
| 4093 | 1 | */ |
|
| 4094 | public static function str_replace($search, $replace, $subject, &$count = null) |
||
| 4098 | |||
| 4099 | /** |
||
| 4100 | * Shuffles all the characters in the string. |
||
| 4101 | * |
||
| 4102 | * @param string $str The input string |
||
| 4103 | * |
||
| 4104 | * @return string The shuffled string. |
||
| 4105 | 1 | */ |
|
| 4106 | 1 | public static function str_shuffle($str) |
|
| 4114 | |||
| 4115 | /** |
||
| 4116 | * Sort all characters according to code points. |
||
| 4117 | * |
||
| 4118 | * @param string $str A UTF-8 string. |
||
| 4119 | * @param bool $unique Sort unique. If true, repeated characters are ignored. |
||
| 4120 | * @param bool $desc If true, will sort characters in reverse code point order. |
||
| 4121 | * |
||
| 4122 | * @return string String of sorted characters |
||
| 4123 | */ |
||
| 4124 | public static function str_sort($str, $unique = false, $desc = false) |
||
| 4140 | |||
| 4141 | /** |
||
| 4142 | * Convert a string to an array. |
||
| 4143 | * |
||
| 4144 | * @param string $str |
||
| 4145 | * @param int $len |
||
| 4146 | * |
||
| 4147 | * @return array |
||
| 4148 | */ |
||
| 4149 | public static function str_split($str, $len = 1) |
||
| 4190 | |||
| 4191 | /** |
||
| 4192 | * Get a binary representation of a specific character. |
||
| 4193 | * |
||
| 4194 | * @param string $str The input character. |
||
| 4195 | * |
||
| 4196 | * @return string |
||
| 4197 | */ |
||
| 4198 | public static function str_to_binary($str) |
||
| 4217 | |||
| 4218 | /** |
||
| 4219 | * US-ASCII transliterations of Unicode text. |
||
| 4220 | * |
||
| 4221 | * Ported Sean M. Burke's Text::Unidecode Perl module (He did all the hard work!) |
||
| 4222 | * Warning: you should only pass this well formed UTF-8! |
||
| 4223 | * Be aware it works by making a copy of the input string which it appends transliterated |
||
| 4224 | * characters to - it uses a PHP output buffer to do this - it means, memory use will increase, |
||
| 4225 | * requiring up to the same amount again as the input string |
||
| 4226 | * |
||
| 4227 | * @see http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm |
||
| 4228 | * |
||
| 4229 | * @author <[email protected]> |
||
| 4230 | * |
||
| 4231 | * @param string $str UTF-8 string to convert |
||
| 4232 | * @param string $unknown Character use if character unknown. (default is ?) |
||
| 4233 | * |
||
| 4234 | * @return string US-ASCII string |
||
| 4235 | */ |
||
| 4236 | public static function str_transliterate($str, $unknown = '?') |
||
| 4328 | |||
| 4329 | /** |
||
| 4330 | * Counts number of words in the UTF-8 string. |
||
| 4331 | * |
||
| 4332 | * @param string $s The input string. |
||
| 4333 | * @param int $format |
||
| 4334 | * @param string $charlist |
||
| 4335 | * |
||
| 4336 | * @return array|float|string The number of words in the string |
||
| 4337 | */ |
||
| 4338 | public static function str_word_count($s, $format = 0, $charlist = '') |
||
| 4363 | |||
| 4364 | /** |
||
| 4365 | * Case-insensitive string comparison. |
||
| 4366 | * |
||
| 4367 | * @param string $str1 |
||
| 4368 | * @param string $str2 |
||
| 4369 | * |
||
| 4370 | * @return int Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. |
||
| 4371 | */ |
||
| 4372 | public static function strcasecmp($str1, $str2) |
||
| 4376 | |||
| 4377 | /** |
||
| 4378 | * String comparison. |
||
| 4379 | * |
||
| 4380 | * @param string $str1 |
||
| 4381 | * @param string $str2 |
||
| 4382 | * |
||
| 4383 | * @return int <strong>< 0</strong> if str1 is less than str2<br /> |
||
| 4384 | * <strong>> 0</strong> if str1 is greater than str2<br /> |
||
| 4385 | * <strong>0</strong> if they are equal. |
||
| 4386 | */ |
||
| 4387 | public static function strcmp($str1, $str2) |
||
| 4394 | |||
| 4395 | /** |
||
| 4396 | * Find length of initial segment not matching mask. |
||
| 4397 | * |
||
| 4398 | * @param string $str |
||
| 4399 | * @param string $charlist |
||
| 4400 | * @param int $start |
||
| 4401 | * @param int $len |
||
| 4402 | * |
||
| 4403 | * @return int|null |
||
| 4404 | */ |
||
| 4405 | public static function strcspn($str, $charlist, $start = 0, $len = 2147483647) |
||
| 4424 | |||
| 4425 | /** |
||
| 4426 | * Makes a UTF-8 string from code points. |
||
| 4427 | * |
||
| 4428 | * @param array $array Integer or Hexadecimal codepoints |
||
| 4429 | * |
||
| 4430 | * @return string UTF-8 encoded string |
||
| 4431 | */ |
||
| 4432 | public static function string($array) |
||
| 4444 | |||
| 4445 | /** |
||
| 4446 | * Checks if string starts with "UTF-8 BOM" character. |
||
| 4447 | * |
||
| 4448 | * @param string $str The input string. |
||
| 4449 | * |
||
| 4450 | * @return bool True if the string has BOM at the start, False otherwise. |
||
| 4451 | */ |
||
| 4452 | public static function string_has_bom($str) |
||
| 4456 | |||
| 4457 | /** |
||
| 4458 | * Strip HTML and PHP tags from a string. |
||
| 4459 | * |
||
| 4460 | * @link http://php.net/manual/en/function.strip-tags.php |
||
| 4461 | * |
||
| 4462 | * @param string $str <p> |
||
| 4463 | * The input string. |
||
| 4464 | * </p> |
||
| 4465 | * @param string $allowable_tags [optional] <p> |
||
| 4466 | * You can use the optional second parameter to specify tags which should |
||
| 4467 | * not be stripped. |
||
| 4468 | * </p> |
||
| 4469 | * <p> |
||
| 4470 | * HTML comments and PHP tags are also stripped. This is hardcoded and |
||
| 4471 | * can not be changed with allowable_tags. |
||
| 4472 | * </p> |
||
| 4473 | * |
||
| 4474 | * @return string the stripped string. |
||
| 4475 | */ |
||
| 4476 | public static function strip_tags($str, $allowable_tags = null) |
||
| 4483 | |||
| 4484 | /** |
||
| 4485 | * Finds position of first occurrence of a string within another, case insensitive. |
||
| 4486 | * |
||
| 4487 | * @link http://php.net/manual/en/function.mb-stripos.php |
||
| 4488 | * |
||
| 4489 | * @param string $haystack <p> |
||
| 4490 | * The string from which to get the position of the first occurrence |
||
| 4491 | * of needle |
||
| 4492 | * </p> |
||
| 4493 | * @param string $needle <p> |
||
| 4494 | * The string to find in haystack |
||
| 4495 | * </p> |
||
| 4496 | * @param int $offset [optional] <p> |
||
| 4497 | * The position in haystack |
||
| 4498 | * to start searching |
||
| 4499 | * </p> |
||
| 4500 | * @param string $encoding |
||
| 4501 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 4502 | * |
||
| 4503 | * @return int Return the numeric position of the first occurrence of |
||
| 4504 | * needle in the haystack |
||
| 4505 | * string, or false if needle is not found. |
||
| 4506 | */ |
||
| 4507 | public static function stripos($haystack, $needle, $offset = null, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 4531 | |||
| 4532 | /** |
||
| 4533 | * Returns all of haystack starting from and including the first occurrence of needle to the end. |
||
| 4534 | * |
||
| 4535 | * @param string $str |
||
| 4536 | * @param string $needle |
||
| 4537 | * @param bool $before_needle |
||
| 4538 | * |
||
| 4539 | * @return false|string |
||
| 4540 | */ |
||
| 4541 | public static function stristr($str, $needle, $before_needle = false) |
||
| 4552 | |||
| 4553 | /** |
||
| 4554 | * Get the string length, not the byte-length! |
||
| 4555 | * |
||
| 4556 | * @link http://php.net/manual/en/function.mb-strlen.php |
||
| 4557 | * |
||
| 4558 | * @param string $str The string being checked for length. |
||
| 4559 | * @param string $encoding Set the charset for e.g. "mb_" function |
||
| 4560 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 4561 | * |
||
| 4562 | * @return int the number of characters in |
||
| 4563 | * string str having character encoding |
||
| 4564 | * encoding. A multi-byte character is |
||
| 4565 | * counted as 1. |
||
| 4566 | */ |
||
| 4567 | public static function strlen($str, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 4589 | |||
| 4590 | /** |
||
| 4591 | * Case insensitive string comparisons using a "natural order" algorithm. |
||
| 4592 | * |
||
| 4593 | * @param string $str1 |
||
| 4594 | * @param string $str2 |
||
| 4595 | * |
||
| 4596 | * @return int Similar to other string comparison functions, this one returns < 0 if str1 is less than str2 > 0 if |
||
| 4597 | * str1 is greater than str2, and 0 if they are equal. |
||
| 4598 | */ |
||
| 4599 | public static function strnatcasecmp($str1, $str2) |
||
| 4603 | |||
| 4604 | /** |
||
| 4605 | * String comparisons using a "natural order" algorithm. |
||
| 4606 | * |
||
| 4607 | * @param string $str1 |
||
| 4608 | * @param string $str2 |
||
| 4609 | * |
||
| 4610 | * @return int Similar to other string comparison functions, this one returns < 0 if str1 is less than str2; > 0 if |
||
| 4611 | * str1 is greater than str2, and 0 if they are equal. |
||
| 4612 | */ |
||
| 4613 | public static function strnatcmp($str1, $str2) |
||
| 4617 | |||
| 4618 | /** |
||
| 4619 | * Case-insensitive string comparison of the first n characters. |
||
| 4620 | * |
||
| 4621 | * @param string $str1 |
||
| 4622 | * @param string $str2 |
||
| 4623 | * @param int $len |
||
| 4624 | * |
||
| 4625 | * @return int Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. |
||
| 4626 | */ |
||
| 4627 | public static function strncasecmp($str1, $str2, $len) |
||
| 4631 | |||
| 4632 | /** |
||
| 4633 | * Comparison of the first n characters. |
||
| 4634 | * |
||
| 4635 | * @param string $str1 |
||
| 4636 | * @param string $str2 |
||
| 4637 | * @param int $len |
||
| 4638 | * |
||
| 4639 | * @return int <strong>< 0</strong> if str1 is less than str2<br /> |
||
| 4640 | * <strong>> 0</strong> if str1 is greater than str2<br /> |
||
| 4641 | * <strong>0</strong> if they are equal |
||
| 4642 | */ |
||
| 4643 | public static function strncmp($str1, $str2, $len) |
||
| 4647 | |||
| 4648 | /** |
||
| 4649 | * Search a string for any of a set of characters. |
||
| 4650 | * |
||
| 4651 | * @param string $s |
||
| 4652 | * @param string $charList |
||
| 4653 | * |
||
| 4654 | * @return string|false |
||
| 4655 | */ |
||
| 4656 | public static function strpbrk($s, $charList) |
||
| 4664 | |||
| 4665 | /** |
||
| 4666 | * Find position of first occurrence of string in a string. |
||
| 4667 | * |
||
| 4668 | * @link http://php.net/manual/en/function.mb-strpos.php |
||
| 4669 | * |
||
| 4670 | * @param string $haystack <p> |
||
| 4671 | * The string being checked. |
||
| 4672 | * </p> |
||
| 4673 | * @param string $needle <p> |
||
| 4674 | * The position counted from the beginning of haystack. |
||
| 4675 | * </p> |
||
| 4676 | * @param int $offset [optional] <p> |
||
| 4677 | * The search offset. If it is not specified, 0 is used. |
||
| 4678 | * </p> |
||
| 4679 | * @param string $encoding |
||
| 4680 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string. |
||
| 4681 | * |
||
| 4682 | * @return int The numeric position of the first occurrence of needle in the haystack string.<br /> |
||
| 4683 | * If needle is not found it returns false. |
||
| 4684 | */ |
||
| 4685 | public static function strpos($haystack, $needle, $offset = 0, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 4739 | |||
| 4740 | /** |
||
| 4741 | * Finds the last occurrence of a character in a string within another. |
||
| 4742 | * |
||
| 4743 | * @link http://php.net/manual/en/function.mb-strrchr.php |
||
| 4744 | * |
||
| 4745 | * @param string $haystack <p> |
||
| 4746 | * The string from which to get the last occurrence |
||
| 4747 | * of needle |
||
| 4748 | * </p> |
||
| 4749 | * @param string $needle <p> |
||
| 4750 | * The string to find in haystack |
||
| 4751 | * </p> |
||
| 4752 | * @param bool $part [optional] <p> |
||
| 4753 | * Determines which portion of haystack |
||
| 4754 | * this function returns. |
||
| 4755 | * If set to true, it returns all of haystack |
||
| 4756 | * from the beginning to the last occurrence of needle. |
||
| 4757 | * If set to false, it returns all of haystack |
||
| 4758 | * from the last occurrence of needle to the end, |
||
| 4759 | * </p> |
||
| 4760 | * @param string $encoding [optional] <p> |
||
| 4761 | * Character encoding name to use. |
||
| 4762 | * If it is omitted, internal character encoding is used. |
||
| 4763 | * </p> |
||
| 4764 | * |
||
| 4765 | * @return string the portion of haystack. |
||
| 4766 | * or false if needle is not found. |
||
| 4767 | */ |
||
| 4768 | public static function strrchr($haystack, $needle, $part = false, $encoding = 'UTF-8') |
||
| 4774 | |||
| 4775 | /** |
||
| 4776 | * Reverses characters order in the string. |
||
| 4777 | * |
||
| 4778 | * @param string $str The input string |
||
| 4779 | * |
||
| 4780 | * @return string The string with characters in the reverse sequence |
||
| 4781 | */ |
||
| 4782 | public static function strrev($str) |
||
| 4786 | |||
| 4787 | /** |
||
| 4788 | * Finds the last occurrence of a character in a string within another, case insensitive. |
||
| 4789 | * |
||
| 4790 | * @link http://php.net/manual/en/function.mb-strrichr.php |
||
| 4791 | * |
||
| 4792 | * @param string $haystack <p> |
||
| 4793 | * The string from which to get the last occurrence |
||
| 4794 | * of needle |
||
| 4795 | * </p> |
||
| 4796 | * @param string $needle <p> |
||
| 4797 | * The string to find in haystack |
||
| 4798 | * </p> |
||
| 4799 | * @param bool $part [optional] <p> |
||
| 4800 | * Determines which portion of haystack |
||
| 4801 | * this function returns. |
||
| 4802 | * If set to true, it returns all of haystack |
||
| 4803 | * from the beginning to the last occurrence of needle. |
||
| 4804 | * If set to false, it returns all of haystack |
||
| 4805 | * from the last occurrence of needle to the end, |
||
| 4806 | * </p> |
||
| 4807 | * @param string $encoding [optional] <p> |
||
| 4808 | * Character encoding name to use. |
||
| 4809 | * If it is omitted, internal character encoding is used. |
||
| 4810 | * </p> |
||
| 4811 | * |
||
| 4812 | * @return string the portion of haystack. |
||
| 4813 | * or false if needle is not found. |
||
| 4814 | */ |
||
| 4815 | public static function strrichr($haystack, $needle, $part = false, $encoding = 'UTF-8') |
||
| 4821 | |||
| 4822 | /** |
||
| 4823 | * Find position of last occurrence of a case-insensitive string. |
||
| 4824 | * |
||
| 4825 | * @param string $haystack The string to look in |
||
| 4826 | * @param string $needle The string to look for |
||
| 4827 | * @param int $offset (Optional) Number of characters to ignore in the beginning or end |
||
| 4828 | * |
||
| 4829 | * @return int The position of offset |
||
| 4830 | */ |
||
| 4831 | public static function strripos($haystack, $needle, $offset = 0) |
||
| 4835 | |||
| 4836 | /** |
||
| 4837 | * Find position of last occurrence of a string in a string. |
||
| 4838 | * |
||
| 4839 | * @link http://php.net/manual/en/function.mb-strrpos.php |
||
| 4840 | * |
||
| 4841 | * @param string $haystack <p> |
||
| 4842 | * The string being checked, for the last occurrence |
||
| 4843 | * of needle |
||
| 4844 | * </p> |
||
| 4845 | * @param string $needle <p> |
||
| 4846 | * The string to find in haystack. |
||
| 4847 | * </p> |
||
| 4848 | * @param int $offset [optional] May be specified to begin searching an arbitrary number of characters into |
||
| 4849 | * the string. Negative values will stop searching at an arbitrary point |
||
| 4850 | * prior to the end of the string. |
||
| 4851 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 4852 | * |
||
| 4853 | * @return int the numeric position of |
||
| 4854 | * the last occurrence of needle in the |
||
| 4855 | * haystack string. If |
||
| 4856 | * needle is not found, it returns false. |
||
| 4857 | */ |
||
| 4858 | public static function strrpos($haystack, $needle, $offset = null, $cleanUtf8 = false) |
||
| 4909 | |||
| 4910 | /** |
||
| 4911 | * Finds the length of the initial segment of a string consisting entirely of characters contained within a given |
||
| 4912 | * mask. |
||
| 4913 | * |
||
| 4914 | * @param string $s |
||
| 4915 | * @param string $mask |
||
| 4916 | * @param int $start |
||
| 4917 | * @param int $len |
||
| 4918 | * |
||
| 4919 | * @return int|null |
||
| 4920 | */ |
||
| 4921 | public static function strspn($s, $mask, $start = 0, $len = 2147483647) |
||
| 4929 | |||
| 4930 | /** |
||
| 4931 | * Returns part of haystack string from the first occurrence of needle to the end of haystack. |
||
| 4932 | * |
||
| 4933 | * @link http://php.net/manual/en/function.grapheme-strstr.php |
||
| 4934 | * |
||
| 4935 | * @param string $haystack <p> |
||
| 4936 | * The input string. Must be valid UTF-8. |
||
| 4937 | * </p> |
||
| 4938 | * @param string $needle <p> |
||
| 4939 | * The string to look for. Must be valid UTF-8. |
||
| 4940 | * </p> |
||
| 4941 | * @param bool $before_needle [optional] <p> |
||
| 4942 | * If <b>TRUE</b>, grapheme_strstr() returns the part of the |
||
| 4943 | * haystack before the first occurrence of the needle (excluding the needle). |
||
| 4944 | * </p> |
||
| 4945 | * |
||
| 4946 | * @return string the portion of string, or FALSE if needle is not found. |
||
| 4947 | */ |
||
| 4948 | public static function strstr($haystack, $needle, $before_needle = false) |
||
| 4954 | |||
| 4955 | /** |
||
| 4956 | * Unicode transformation for case-less matching. |
||
| 4957 | * |
||
| 4958 | * @link http://unicode.org/reports/tr21/tr21-5.html |
||
| 4959 | * |
||
| 4960 | * @param string $str |
||
| 4961 | * @param bool $full |
||
| 4962 | * |
||
| 4963 | * @return string |
||
| 4964 | */ |
||
| 4965 | public static function strtocasefold($str, $full = true) |
||
| 4992 | |||
| 4993 | /** |
||
| 4994 | * (PHP 4 >= 4.3.0, PHP 5)<br/> |
||
| 4995 | * Make a string lowercase. |
||
| 4996 | * |
||
| 4997 | * @link http://php.net/manual/en/function.mb-strtolower.php |
||
| 4998 | * |
||
| 4999 | * @param string $str <p> |
||
| 5000 | * The string being lowercased. |
||
| 5001 | * </p> |
||
| 5002 | * @param string $encoding |
||
| 5003 | * |
||
| 5004 | * @return string str with all alphabetic characters converted to lowercase. |
||
| 5005 | */ |
||
| 5006 | public static function strtolower($str, $encoding = 'UTF-8') |
||
| 5019 | |||
| 5020 | /** |
||
| 5021 | * Generic case sensitive transformation for collation matching. |
||
| 5022 | * |
||
| 5023 | * @param string $s |
||
| 5024 | * |
||
| 5025 | * @return string |
||
| 5026 | */ |
||
| 5027 | protected static function strtonatfold($s) |
||
| 5031 | |||
| 5032 | /** |
||
| 5033 | * Make a string uppercase. |
||
| 5034 | * |
||
| 5035 | * @link http://php.net/manual/en/function.mb-strtoupper.php |
||
| 5036 | * |
||
| 5037 | * @param string $str <p> |
||
| 5038 | * The string being uppercased. |
||
| 5039 | * </p> |
||
| 5040 | * @param string $encoding |
||
| 5041 | * |
||
| 5042 | * @return string str with all alphabetic characters converted to uppercase. |
||
| 5043 | */ |
||
| 5044 | public static function strtoupper($str, $encoding = 'UTF-8') |
||
| 5075 | |||
| 5076 | /** |
||
| 5077 | * Translate characters or replace sub-strings. |
||
| 5078 | * |
||
| 5079 | * @param string $s |
||
| 5080 | * @param string $from |
||
| 5081 | * @param string $to |
||
| 5082 | * |
||
| 5083 | * @return string |
||
| 5084 | */ |
||
| 5085 | public static function strtr($s, $from, $to = INF) |
||
| 5104 | |||
| 5105 | /** |
||
| 5106 | * Return the width of a string. |
||
| 5107 | * |
||
| 5108 | * @param string $s |
||
| 5109 | * |
||
| 5110 | * @return int |
||
| 5111 | */ |
||
| 5112 | public static function strwidth($s) |
||
| 5119 | |||
| 5120 | /** |
||
| 5121 | * Get part of a string. |
||
| 5122 | * |
||
| 5123 | * @link http://php.net/manual/en/function.mb-substr.php |
||
| 5124 | * |
||
| 5125 | * @param string $str <p> |
||
| 5126 | * The string being checked. |
||
| 5127 | * </p> |
||
| 5128 | * @param int $start <p> |
||
| 5129 | * The first position used in str. |
||
| 5130 | * </p> |
||
| 5131 | * @param int $length [optional] <p> |
||
| 5132 | * The maximum length of the returned string. |
||
| 5133 | * </p> |
||
| 5134 | * @param string $encoding |
||
| 5135 | * @param boolean $cleanUtf8 Clean non UTF-8 chars from the string |
||
| 5136 | * |
||
| 5137 | * @return string mb_substr returns the portion of |
||
| 5138 | * str specified by the start and length parameters. |
||
| 5139 | */ |
||
| 5140 | public static function substr($str, $start = 0, $length = null, $encoding = 'UTF-8', $cleanUtf8 = false) |
||
| 5186 | |||
| 5187 | /** |
||
| 5188 | * Binary safe comparison of two strings from an offset, up to length characters. |
||
| 5189 | * |
||
| 5190 | * @param string $main_str The main string being compared. |
||
| 5191 | * @param string $str The secondary string being compared. |
||
| 5192 | * @param int $offset The start position for the comparison. If negative, it starts counting from the |
||
| 5193 | * end of the string. |
||
| 5194 | * @param int $length The length of the comparison. The default value is the largest of the length of |
||
| 5195 | * the str compared to the length of main_str less the offset. |
||
| 5196 | * @param boolean $case_insensitivity If case_insensitivity is TRUE, comparison is case insensitive. |
||
| 5197 | * |
||
| 5198 | 1 | * @return int |
|
| 5199 | */ |
||
| 5200 | 1 | public static function substr_compare($main_str, $str, $offset, $length = 2147483647, $case_insensitivity = false) |
|
| 5207 | |||
| 5208 | /** |
||
| 5209 | * Count the number of sub-string occurrences. |
||
| 5210 | * |
||
| 5211 | * @param string $haystack The string to search in. |
||
| 5212 | * @param string $needle The string to search for. |
||
| 5213 | * @param int $offset The offset where to start counting. |
||
| 5214 | * @param int $length The maximum length after the specified offset to search for the substring. |
||
| 5215 | 1 | * |
|
| 5216 | * @return int number of occurrences of $needle |
||
| 5217 | */ |
||
| 5218 | public static function substr_count($haystack, $needle, $offset = 0, $length = null) |
||
| 5234 | 1 | ||
| 5235 | /** |
||
| 5236 | 1 | * Replace text within a portion of a string. |
|
| 5237 | * |
||
| 5238 | * source: https://gist.github.com/stemar/8287074 |
||
| 5239 | * |
||
| 5240 | * @param string|array $str |
||
| 5241 | * @param string|array $replacement |
||
| 5242 | * @param int $start |
||
| 5243 | * @param null|int $length |
||
| 5244 | * |
||
| 5245 | * @return array|string |
||
| 5246 | */ |
||
| 5247 | 8 | public static function substr_replace($str, $replacement, $start, $length = null) |
|
| 5313 | |||
| 5314 | /** |
||
| 5315 | * Returns a case swapped version of the string. |
||
| 5316 | * |
||
| 5317 | * @param string $str |
||
| 5318 | * @param string $encoding |
||
| 5319 | * |
||
| 5320 | 1 | * @return string each character's case swapped |
|
| 5321 | */ |
||
| 5322 | 1 | public static function swapCase($str, $encoding = 'UTF-8') |
|
| 5348 | |||
| 5349 | /** |
||
| 5350 | * alias for "UTF8::to_ascii()" |
||
| 5351 | * |
||
| 5352 | * @param string $s The input string e.g. a UTF-8 String |
||
| 5353 | * @param string $subst_chr |
||
| 5354 | * |
||
| 5355 | 12 | * @return string |
|
| 5356 | */ |
||
| 5357 | 12 | public static function toAscii($s, $subst_chr = '?') |
|
| 5361 | |||
| 5362 | /** |
||
| 5363 | * alias for "UTF8::to_latin1()" |
||
| 5364 | * |
||
| 5365 | * @param $str |
||
| 5366 | * |
||
| 5367 | * @return string |
||
| 5368 | */ |
||
| 5369 | public static function toLatin1($str) |
||
| 5373 | |||
| 5374 | /** |
||
| 5375 | 13 | * alias for "UTF8::to_utf8" |
|
| 5376 | 13 | * |
|
| 5377 | 1 | * @param string $str |
|
| 5378 | 1 | * |
|
| 5379 | 12 | * @return string |
|
| 5380 | */ |
||
| 5381 | 13 | public static function toUTF8($str) |
|
| 5385 | |||
| 5386 | 13 | /** |
|
| 5387 | * convert to ASCII |
||
| 5388 | * |
||
| 5389 | * @param string $s The input string e.g. a UTF-8 String |
||
| 5390 | * @param string $subst_chr |
||
| 5391 | * |
||
| 5392 | * @return string |
||
| 5393 | */ |
||
| 5394 | public static function to_ascii($s, $subst_chr = '?') |
||
| 5465 | |||
| 5466 | /** |
||
| 5467 | * alias for "UTF8::to_win1252()" |
||
| 5468 | * |
||
| 5469 | * @param string $str |
||
| 5470 | * |
||
| 5471 | * @return array|string |
||
| 5472 | */ |
||
| 5473 | public static function to_iso8859($str) |
||
| 5477 | |||
| 5478 | /** |
||
| 5479 | * alias for "UTF8::to_win1252()" |
||
| 5480 | * |
||
| 5481 | * @param string|array $str |
||
| 5482 | * |
||
| 5483 | * @return string|array |
||
| 5484 | */ |
||
| 5485 | public static function to_latin1($str) |
||
| 5489 | |||
| 5490 | /** |
||
| 5491 | * This function leaves UTF8 characters alone, while converting almost all non-UTF8 to UTF8. |
||
| 5492 | * |
||
| 5493 | * - It assumes that the encoding of the original string is either Windows-1252 or ISO 8859-1. |
||
| 5494 | * |
||
| 5495 | * - It may fail to convert characters to UTF-8 if they fall into one of these scenarios: |
||
| 5496 | * |
||
| 5497 | * 1) when any of these characters: ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß |
||
| 5498 | * are followed by any of these: ("group B") |
||
| 5499 | 1 | * ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶•¸¹º»¼½¾¿ |
|
| 5500 | * For example: %ABREPRESENT%C9%BB. «REPRESENTÉ» |
||
| 5501 | 1 | * The "«" (%AB) character will be converted, but the "É" followed by "»" (%C9%BB) |
|
| 5502 | * is also a valid unicode character, and will be left unchanged. |
||
| 5503 | * |
||
| 5504 | * 2) when any of these: àáâãäåæçèéêëìíîï are followed by TWO chars from group B, |
||
| 5505 | * 3) when any of these: ðñòó are followed by THREE chars from group B. |
||
| 5506 | * |
||
| 5507 | * @param string $str Any string or array. |
||
| 5508 | * |
||
| 5509 | * @return string The same string, but UTF8 encoded. |
||
| 5510 | */ |
||
| 5511 | public static function to_utf8($str) |
||
| 5617 | |||
| 5618 | /** |
||
| 5619 | * Convert a string into win1252. |
||
| 5620 | * |
||
| 5621 | 1 | * @param string|array $str |
|
| 5622 | 1 | * |
|
| 5623 | * @return string|array |
||
| 5624 | */ |
||
| 5625 | protected static function to_win1252($str) |
||
| 5641 | |||
| 5642 | /** |
||
| 5643 | * Strip whitespace or other characters from beginning or end of a UTF-8 string. |
||
| 5644 | * |
||
| 5645 | * INFO: This is slower then "trim()" |
||
| 5646 | * |
||
| 5647 | * But we can only use the original-function, if we use <= 7-Bit in the string / chars |
||
| 5648 | * but the check for ACSII (7-Bit) cost more time, then we can safe here. |
||
| 5649 | * |
||
| 5650 | * @param string $str The string to be trimmed |
||
| 5651 | * @param string $chars Optional characters to be stripped |
||
| 5652 | * |
||
| 5653 | * @return string The trimmed string |
||
| 5654 | */ |
||
| 5655 | public static function trim($str = '', $chars = INF) |
||
| 5670 | |||
| 5671 | /** |
||
| 5672 | * Makes string's first char uppercase. |
||
| 5673 | * |
||
| 5674 | * @param string $str The input string |
||
| 5675 | * |
||
| 5676 | * @return string The resulting string |
||
| 5677 | */ |
||
| 5678 | public static function ucfirst($str) |
||
| 5682 | |||
| 5683 | 2 | /** |
|
| 5684 | 2 | * alias for "UTF8::ucfirst" |
|
| 5685 | 2 | * |
|
| 5686 | * @param $str |
||
| 5687 | 2 | * |
|
| 5688 | * @return string |
||
| 5689 | 2 | */ |
|
| 5690 | public static function ucword($str) |
||
| 5694 | 2 | ||
| 5695 | 2 | /** |
|
| 5696 | 2 | * Uppercase for all words in the string. |
|
| 5697 | * |
||
| 5698 | 1 | * @param string $str |
|
| 5699 | 1 | * @param array $exceptions |
|
| 5700 | 1 | * |
|
| 5701 | * @return string |
||
| 5702 | */ |
||
| 5703 | public static function ucwords($str, $exceptions = array()) |
||
| 5736 | |||
| 5737 | /** |
||
| 5738 | * Multi decode html entity & fix urlencoded-win1252-chars. |
||
| 5739 | * |
||
| 5740 | * e.g: |
||
| 5741 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 5742 | * 'D%FCsseldorf' => 'Düsseldorf' |
||
| 5743 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 5744 | * 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' |
||
| 5745 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 5746 | * 'D%C3%BCsseldorf' => 'Düsseldorf' |
||
| 5747 | * 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' |
||
| 5748 | * 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf' |
||
| 5749 | * |
||
| 5750 | * @param string $str |
||
| 5751 | * |
||
| 5752 | * @return string |
||
| 5753 | */ |
||
| 5754 | public static function urldecode($str) |
||
| 5777 | |||
| 5778 | /** |
||
| 5779 | * Return a array with "urlencoded"-win1252 -> UTF-8 |
||
| 5780 | * |
||
| 5781 | * @return mixed |
||
| 5782 | */ |
||
| 5783 | protected static function urldecode_fix_win1252_chars() |
||
| 6014 | |||
| 6015 | /** |
||
| 6016 | * Decodes an UTF-8 string to ISO-8859-1. |
||
| 6017 | * |
||
| 6018 | * @param string $str |
||
| 6019 | * |
||
| 6020 | * @return string |
||
| 6021 | */ |
||
| 6022 | public static function utf8_decode($str) |
||
| 6045 | |||
| 6046 | /** |
||
| 6047 | * Encodes an ISO-8859-1 string to UTF-8. |
||
| 6048 | * |
||
| 6049 | * @param string $str |
||
| 6050 | * |
||
| 6051 | * @return string |
||
| 6052 | */ |
||
| 6053 | public static function utf8_encode($str) |
||
| 6072 | |||
| 6073 | /** |
||
| 6074 | * fix -> utf8-win1252 chars |
||
| 6075 | * |
||
| 6076 | * If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1 |
||
| 6077 | * (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. |
||
| 6078 | * See: http://en.wikipedia.org/wiki/Windows-1252 |
||
| 6079 | * |
||
| 6080 | * @deprecated use "UTF8::fix_simple_utf8()" |
||
| 6081 | * |
||
| 6082 | * @param string $str |
||
| 6083 | * |
||
| 6084 | * @return string |
||
| 6085 | */ |
||
| 6086 | public static function utf8_fix_win1252_chars($str) |
||
| 6090 | |||
| 6091 | /** |
||
| 6092 | * Returns an array with all utf8 whitespace characters. |
||
| 6093 | * |
||
| 6094 | * @see : http://www.bogofilter.org/pipermail/bogofilter/2003-March/001889.html |
||
| 6095 | * |
||
| 6096 | * @author: Derek E. [email protected] |
||
| 6097 | * |
||
| 6098 | * @return array an array with all known whitespace characters as values and the type of whitespace as keys |
||
| 6099 | * as defined in above URL |
||
| 6100 | */ |
||
| 6101 | public static function whitespace_table() |
||
| 6105 | |||
| 6106 | /** |
||
| 6107 | * Limit the number of words in a string. |
||
| 6108 | * |
||
| 6109 | * @param string $str |
||
| 6110 | * @param int $words |
||
| 6111 | * @param string $strAddOn |
||
| 6112 | * |
||
| 6113 | * @return string |
||
| 6114 | */ |
||
| 6115 | public static function words_limit($str, $words = 100, $strAddOn = '...') |
||
| 6135 | |||
| 6136 | /** |
||
| 6137 | * Wraps a string to a given number of characters. |
||
| 6138 | * |
||
| 6139 | * @param string $str |
||
| 6140 | * @param int $width |
||
| 6141 | * @param string $break |
||
| 6142 | * @param bool $cut |
||
| 6143 | * |
||
| 6144 | * @return false|string Returns the given string wrapped at the specified length. |
||
| 6145 | */ |
||
| 6146 | public static function wordwrap($str, $width = 75, $break = "\n", $cut = false) |
||
| 6202 | |||
| 6203 | /** |
||
| 6204 | * Returns an array of Unicode White Space characters. |
||
| 6205 | * |
||
| 6206 | * @return array An array with numeric code point as key and White Space Character as value. |
||
| 6207 | */ |
||
| 6208 | public static function ws() |
||
| 6212 | |||
| 6213 | } |
||
| 6214 |
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: