Exceptions
5 days ago
apache.php
5 days ago
apcu.php
5 days ago
array.php
5 days ago
bzip2.php
5 days ago
calendar.php
5 days ago
classobj.php
5 days ago
com.php
5 days ago
cubrid.php
5 days ago
curl.php
5 days ago
datetime.php
5 days ago
dir.php
5 days ago
eio.php
5 days ago
errorfunc.php
5 days ago
exec.php
5 days ago
fileinfo.php
5 days ago
filesystem.php
5 days ago
filter.php
5 days ago
fpm.php
5 days ago
ftp.php
5 days ago
funchand.php
5 days ago
functionsList.php
5 days ago
gmp.php
5 days ago
gnupg.php
5 days ago
hash.php
5 days ago
ibase.php
5 days ago
ibmDb2.php
5 days ago
iconv.php
5 days ago
image.php
5 days ago
imap.php
5 days ago
info.php
5 days ago
ingres-ii.php
5 days ago
inotify.php
5 days ago
json.php
5 days ago
ldap.php
5 days ago
libxml.php
5 days ago
lzf.php
5 days ago
mailparse.php
5 days ago
mbstring.php
5 days ago
misc.php
5 days ago
msql.php
5 days ago
mysql.php
5 days ago
mysqli.php
5 days ago
mysqlndMs.php
5 days ago
mysqlndQc.php
5 days ago
network.php
5 days ago
oci8.php
5 days ago
opcache.php
5 days ago
openssl.php
5 days ago
outcontrol.php
5 days ago
password.php
5 days ago
pcntl.php
5 days ago
pcre.php
5 days ago
pdf.php
5 days ago
pgsql.php
5 days ago
posix.php
5 days ago
ps.php
5 days ago
pspell.php
5 days ago
readline.php
5 days ago
rpminfo.php
5 days ago
rrd.php
5 days ago
sem.php
5 days ago
session.php
5 days ago
shmop.php
5 days ago
simplexml.php
5 days ago
sockets.php
5 days ago
sodium.php
5 days ago
solr.php
5 days ago
spl.php
5 days ago
sqlsrv.php
5 days ago
ssdeep.php
5 days ago
ssh2.php
5 days ago
stream.php
5 days ago
strings.php
5 days ago
swoole.php
5 days ago
uodbc.php
5 days ago
uopz.php
5 days ago
url.php
5 days ago
var.php
5 days ago
xdiff.php
5 days ago
xml.php
5 days ago
xmlrpc.php
5 days ago
yaml.php
5 days ago
yaz.php
5 days ago
zip.php
5 days ago
zlib.php
5 days ago
mbstring.php
492 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\MbstringException; |
| 6 | /** |
| 7 | * |
| 8 | * |
| 9 | * @param int $cp |
| 10 | * @param string $encoding |
| 11 | * @return string Returns a specific character. |
| 12 | * @throws MbstringException |
| 13 | * |
| 14 | */ |
| 15 | function mb_chr(int $cp, string $encoding = null): string |
| 16 | { |
| 17 | error_clear_last(); |
| 18 | if ($encoding !== null) { |
| 19 | $result = \mb_chr($cp, $encoding); |
| 20 | } else { |
| 21 | $result = \mb_chr($cp); |
| 22 | } |
| 23 | if ($result === \false) { |
| 24 | throw MbstringException::createFromPhpError(); |
| 25 | } |
| 26 | return $result; |
| 27 | } |
| 28 | /** |
| 29 | * Sets the automatic character |
| 30 | * encoding detection order to encoding_list. |
| 31 | * |
| 32 | * @param mixed $encoding_list encoding_list is an array or |
| 33 | * comma separated list of character encoding. See supported encodings. |
| 34 | * |
| 35 | * If encoding_list is omitted, it returns |
| 36 | * the current character encoding detection order as array. |
| 37 | * |
| 38 | * This setting affects mb_detect_encoding and |
| 39 | * mb_send_mail. |
| 40 | * |
| 41 | * mbstring currently implements the following |
| 42 | * encoding detection filters. If there is an invalid byte sequence |
| 43 | * for the following encodings, encoding detection will fail. |
| 44 | * |
| 45 | * For ISO-8859-*, mbstring |
| 46 | * always detects as ISO-8859-*. |
| 47 | * |
| 48 | * For UTF-16, UTF-32, |
| 49 | * UCS2 and UCS4, encoding |
| 50 | * detection will fail always. |
| 51 | * @return bool|array When setting the encoding detection order, TRUE is returned on success. |
| 52 | * |
| 53 | * When getting the encoding detection order, an ordered array of the encodings is returned. |
| 54 | * @throws MbstringException |
| 55 | * |
| 56 | */ |
| 57 | function mb_detect_order($encoding_list = null) |
| 58 | { |
| 59 | error_clear_last(); |
| 60 | if ($encoding_list !== null) { |
| 61 | $result = \mb_detect_order($encoding_list); |
| 62 | } else { |
| 63 | $result = \mb_detect_order(); |
| 64 | } |
| 65 | if ($result === \false) { |
| 66 | throw MbstringException::createFromPhpError(); |
| 67 | } |
| 68 | return $result; |
| 69 | } |
| 70 | /** |
| 71 | * Returns an array of aliases for a known encoding type. |
| 72 | * |
| 73 | * @param string $encoding The encoding type being checked, for aliases. |
| 74 | * @return array Returns a numerically indexed array of encoding aliases on success |
| 75 | * @throws MbstringException |
| 76 | * |
| 77 | */ |
| 78 | function mb_encoding_aliases(string $encoding): array |
| 79 | { |
| 80 | error_clear_last(); |
| 81 | $result = \mb_encoding_aliases($encoding); |
| 82 | if ($result === \false) { |
| 83 | throw MbstringException::createFromPhpError(); |
| 84 | } |
| 85 | return $result; |
| 86 | } |
| 87 | /** |
| 88 | * Scans string for matches to |
| 89 | * pattern, then replaces the matched text |
| 90 | * with the output of callback function. |
| 91 | * |
| 92 | * The behavior of this function is almost identical to mb_ereg_replace, |
| 93 | * except for the fact that instead of |
| 94 | * replacement parameter, one should specify a |
| 95 | * callback. |
| 96 | * |
| 97 | * @param string $pattern The regular expression pattern. |
| 98 | * |
| 99 | * Multibyte characters may be used in pattern. |
| 100 | * @param callable $callback A callback that will be called and passed an array of matched elements |
| 101 | * in the subject string. The callback should |
| 102 | * return the replacement string. |
| 103 | * |
| 104 | * You'll often need the callback function |
| 105 | * for a mb_ereg_replace_callback in just one place. |
| 106 | * In this case you can use an |
| 107 | * anonymous function to |
| 108 | * declare the callback within the call to |
| 109 | * mb_ereg_replace_callback. By doing it this way |
| 110 | * you have all information for the call in one place and do not |
| 111 | * clutter the function namespace with a callback function's name |
| 112 | * not used anywhere else. |
| 113 | * @param string $string The string being checked. |
| 114 | * @param string $option The search option. See mb_regex_set_options for explanation. |
| 115 | * @return string The resultant string on success. |
| 116 | * @throws MbstringException |
| 117 | * |
| 118 | */ |
| 119 | function mb_ereg_replace_callback(string $pattern, callable $callback, string $string, string $option = "msr"): string |
| 120 | { |
| 121 | error_clear_last(); |
| 122 | $result = \mb_ereg_replace_callback($pattern, $callback, $string, $option); |
| 123 | if ($result === \false) { |
| 124 | throw MbstringException::createFromPhpError(); |
| 125 | } |
| 126 | return $result; |
| 127 | } |
| 128 | /** |
| 129 | * |
| 130 | * |
| 131 | * @param string $pattern The regular expression pattern. |
| 132 | * |
| 133 | * Multibyte characters may be used in pattern. |
| 134 | * @param string $replacement The replacement text. |
| 135 | * @param string $string The string being checked. |
| 136 | * @param string $option |
| 137 | * @return string The resultant string on success. |
| 138 | * @throws MbstringException |
| 139 | * |
| 140 | */ |
| 141 | function mb_ereg_replace(string $pattern, string $replacement, string $string, string $option = "msr"): string |
| 142 | { |
| 143 | error_clear_last(); |
| 144 | $result = \mb_ereg_replace($pattern, $replacement, $string, $option); |
| 145 | if ($result === \false) { |
| 146 | throw MbstringException::createFromPhpError(); |
| 147 | } |
| 148 | return $result; |
| 149 | } |
| 150 | /** |
| 151 | * |
| 152 | * |
| 153 | * @return array |
| 154 | * @throws MbstringException |
| 155 | * |
| 156 | */ |
| 157 | function mb_ereg_search_getregs(): array |
| 158 | { |
| 159 | error_clear_last(); |
| 160 | $result = \mb_ereg_search_getregs(); |
| 161 | if ($result === \false) { |
| 162 | throw MbstringException::createFromPhpError(); |
| 163 | } |
| 164 | return $result; |
| 165 | } |
| 166 | /** |
| 167 | * mb_ereg_search_init sets |
| 168 | * string and pattern |
| 169 | * for a multibyte regular expression. These values are used for |
| 170 | * mb_ereg_search, |
| 171 | * mb_ereg_search_pos, and |
| 172 | * mb_ereg_search_regs. |
| 173 | * |
| 174 | * @param string $string The search string. |
| 175 | * @param string $pattern The search pattern. |
| 176 | * @param string $option The search option. See mb_regex_set_options for explanation. |
| 177 | * @throws MbstringException |
| 178 | * |
| 179 | */ |
| 180 | function mb_ereg_search_init(string $string, string $pattern = null, string $option = "msr"): void |
| 181 | { |
| 182 | error_clear_last(); |
| 183 | if ($option !== "msr") { |
| 184 | $result = \mb_ereg_search_init($string, $pattern, $option); |
| 185 | } elseif ($pattern !== null) { |
| 186 | $result = \mb_ereg_search_init($string, $pattern); |
| 187 | } else { |
| 188 | $result = \mb_ereg_search_init($string); |
| 189 | } |
| 190 | if ($result === \false) { |
| 191 | throw MbstringException::createFromPhpError(); |
| 192 | } |
| 193 | } |
| 194 | /** |
| 195 | * Returns the matched part of a multibyte regular expression. |
| 196 | * |
| 197 | * @param string $pattern The search pattern. |
| 198 | * @param string $option The search option. See mb_regex_set_options for explanation. |
| 199 | * @return array |
| 200 | * @throws MbstringException |
| 201 | * |
| 202 | */ |
| 203 | function mb_ereg_search_regs(string $pattern = null, string $option = "ms"): array |
| 204 | { |
| 205 | error_clear_last(); |
| 206 | if ($option !== "ms") { |
| 207 | $result = \mb_ereg_search_regs($pattern, $option); |
| 208 | } elseif ($pattern !== null) { |
| 209 | $result = \mb_ereg_search_regs($pattern); |
| 210 | } else { |
| 211 | $result = \mb_ereg_search_regs(); |
| 212 | } |
| 213 | if ($result === \false) { |
| 214 | throw MbstringException::createFromPhpError(); |
| 215 | } |
| 216 | return $result; |
| 217 | } |
| 218 | /** |
| 219 | * |
| 220 | * |
| 221 | * @param int $position The position to set. If it is negative, it counts from the end of the string. |
| 222 | * @throws MbstringException |
| 223 | * |
| 224 | */ |
| 225 | function mb_ereg_search_setpos(int $position): void |
| 226 | { |
| 227 | error_clear_last(); |
| 228 | $result = \mb_ereg_search_setpos($position); |
| 229 | if ($result === \false) { |
| 230 | throw MbstringException::createFromPhpError(); |
| 231 | } |
| 232 | } |
| 233 | /** |
| 234 | * |
| 235 | * |
| 236 | * @param string $pattern The regular expression pattern. Multibyte characters may be used. The case will be ignored. |
| 237 | * @param string $replace The replacement text. |
| 238 | * @param string $string The searched string. |
| 239 | * @param string $option |
| 240 | * @return string The resultant string. |
| 241 | * @throws MbstringException |
| 242 | * |
| 243 | */ |
| 244 | function mb_eregi_replace(string $pattern, string $replace, string $string, string $option = "msri"): string |
| 245 | { |
| 246 | error_clear_last(); |
| 247 | $result = \mb_eregi_replace($pattern, $replace, $string, $option); |
| 248 | if ($result === \false) { |
| 249 | throw MbstringException::createFromPhpError(); |
| 250 | } |
| 251 | return $result; |
| 252 | } |
| 253 | /** |
| 254 | * Set/Get the HTTP output character encoding. |
| 255 | * Output after this function is called will be converted from the set internal encoding to encoding. |
| 256 | * |
| 257 | * @param string $encoding If encoding is set, |
| 258 | * mb_http_output sets the HTTP output character |
| 259 | * encoding to encoding. |
| 260 | * |
| 261 | * If encoding is omitted, |
| 262 | * mb_http_output returns the current HTTP output |
| 263 | * character encoding. |
| 264 | * @return string|bool If encoding is omitted, |
| 265 | * mb_http_output returns the current HTTP output |
| 266 | * character encoding. Otherwise, |
| 267 | * Returns TRUE on success. |
| 268 | * @throws MbstringException |
| 269 | * |
| 270 | */ |
| 271 | function mb_http_output(string $encoding = null) |
| 272 | { |
| 273 | error_clear_last(); |
| 274 | if ($encoding !== null) { |
| 275 | $result = \mb_http_output($encoding); |
| 276 | } else { |
| 277 | $result = \mb_http_output(); |
| 278 | } |
| 279 | if ($result === \false) { |
| 280 | throw MbstringException::createFromPhpError(); |
| 281 | } |
| 282 | return $result; |
| 283 | } |
| 284 | /** |
| 285 | * Set/Get the internal character encoding |
| 286 | * |
| 287 | * @param string $encoding encoding is the character encoding name |
| 288 | * used for the HTTP input character encoding conversion, HTTP output |
| 289 | * character encoding conversion, and the default character encoding |
| 290 | * for string functions defined by the mbstring module. |
| 291 | * You should notice that the internal encoding is totally different from the one for multibyte regex. |
| 292 | * @return string|bool If encoding is set, then |
| 293 | * Returns TRUE on success. |
| 294 | * In this case, the character encoding for multibyte regex is NOT changed. |
| 295 | * If encoding is omitted, then |
| 296 | * the current character encoding name is returned. |
| 297 | * @throws MbstringException |
| 298 | * |
| 299 | */ |
| 300 | function mb_internal_encoding(string $encoding = null) |
| 301 | { |
| 302 | error_clear_last(); |
| 303 | if ($encoding !== null) { |
| 304 | $result = \mb_internal_encoding($encoding); |
| 305 | } else { |
| 306 | $result = \mb_internal_encoding(); |
| 307 | } |
| 308 | if ($result === \false) { |
| 309 | throw MbstringException::createFromPhpError(); |
| 310 | } |
| 311 | return $result; |
| 312 | } |
| 313 | /** |
| 314 | * |
| 315 | * |
| 316 | * @param string $str |
| 317 | * @param string $encoding |
| 318 | * @return int Returns a code point of character. |
| 319 | * @throws MbstringException |
| 320 | * |
| 321 | */ |
| 322 | function mb_ord(string $str, string $encoding = null): int |
| 323 | { |
| 324 | error_clear_last(); |
| 325 | if ($encoding !== null) { |
| 326 | $result = \mb_ord($str, $encoding); |
| 327 | } else { |
| 328 | $result = \mb_ord($str); |
| 329 | } |
| 330 | if ($result === \false) { |
| 331 | throw MbstringException::createFromPhpError(); |
| 332 | } |
| 333 | return $result; |
| 334 | } |
| 335 | /** |
| 336 | * Parses GET/POST/COOKIE data and |
| 337 | * sets global variables. Since PHP does not provide raw POST/COOKIE |
| 338 | * data, it can only be used for GET data for now. It parses URL |
| 339 | * encoded data, detects encoding, converts coding to internal |
| 340 | * encoding and set values to the result array or |
| 341 | * global variables. |
| 342 | * |
| 343 | * @param string $encoded_string The URL encoded data. |
| 344 | * @param array|null $result An array containing decoded and character encoded converted values. |
| 345 | * @throws MbstringException |
| 346 | * |
| 347 | */ |
| 348 | function mb_parse_str(string $encoded_string, ?array &$result): void |
| 349 | { |
| 350 | error_clear_last(); |
| 351 | $result = \mb_parse_str($encoded_string, $result); |
| 352 | if ($result === \false) { |
| 353 | throw MbstringException::createFromPhpError(); |
| 354 | } |
| 355 | } |
| 356 | /** |
| 357 | * Set/Get character encoding for a multibyte regex. |
| 358 | * |
| 359 | * @param string $encoding The encoding |
| 360 | * parameter is the character encoding. If it is omitted, the internal character |
| 361 | * encoding value will be used. |
| 362 | * @return string|bool |
| 363 | * @throws MbstringException |
| 364 | * |
| 365 | */ |
| 366 | function mb_regex_encoding(string $encoding = null) |
| 367 | { |
| 368 | error_clear_last(); |
| 369 | if ($encoding !== null) { |
| 370 | $result = \mb_regex_encoding($encoding); |
| 371 | } else { |
| 372 | $result = \mb_regex_encoding(); |
| 373 | } |
| 374 | if ($result === \false) { |
| 375 | throw MbstringException::createFromPhpError(); |
| 376 | } |
| 377 | return $result; |
| 378 | } |
| 379 | /** |
| 380 | * Sends email. Headers and messages are converted and encoded according |
| 381 | * to the mb_language setting. It's a wrapper function |
| 382 | * for mail, so see also mail for details. |
| 383 | * |
| 384 | * @param string $to The mail addresses being sent to. Multiple |
| 385 | * recipients may be specified by putting a comma between each |
| 386 | * address in to. |
| 387 | * This parameter is not automatically encoded. |
| 388 | * @param string $subject The subject of the mail. |
| 389 | * @param string $message The message of the mail. |
| 390 | * @param string|array|null $additional_headers String or array to be inserted at the end of the email header. |
| 391 | * |
| 392 | * This is typically used to add extra headers (From, Cc, and Bcc). |
| 393 | * Multiple extra headers should be separated with a CRLF (\r\n). |
| 394 | * Validate parameter not to be injected unwanted headers by attackers. |
| 395 | * |
| 396 | * If an array is passed, its keys are the header names and its |
| 397 | * values are the respective header values. |
| 398 | * |
| 399 | * When sending mail, the mail must contain |
| 400 | * a From header. This can be set with the |
| 401 | * additional_headers parameter, or a default |
| 402 | * can be set in php.ini. |
| 403 | * |
| 404 | * Failing to do this will result in an error |
| 405 | * message similar to Warning: mail(): "sendmail_from" not |
| 406 | * set in php.ini or custom "From:" header missing. |
| 407 | * The From header sets also |
| 408 | * Return-Path under Windows. |
| 409 | * |
| 410 | * If messages are not received, try using a LF (\n) only. |
| 411 | * Some Unix mail transfer agents (most notably |
| 412 | * qmail) replace LF by CRLF |
| 413 | * automatically (which leads to doubling CR if CRLF is used). |
| 414 | * This should be a last resort, as it does not comply with |
| 415 | * RFC 2822. |
| 416 | * @param string $additional_parameter additional_parameter is a MTA command line |
| 417 | * parameter. It is useful when setting the correct Return-Path |
| 418 | * header when using sendmail. |
| 419 | * |
| 420 | * This parameter is escaped by escapeshellcmd internally |
| 421 | * to prevent command execution. escapeshellcmd prevents |
| 422 | * command execution, but allows to add additional parameters. For security reason, |
| 423 | * this parameter should be validated. |
| 424 | * |
| 425 | * Since escapeshellcmd is applied automatically, some characters |
| 426 | * that are allowed as email addresses by internet RFCs cannot be used. Programs |
| 427 | * that are required to use these characters mail cannot be used. |
| 428 | * |
| 429 | * The user that the webserver runs as should be added as a trusted user to the |
| 430 | * sendmail configuration to prevent a 'X-Warning' header from being added |
| 431 | * to the message when the envelope sender (-f) is set using this method. |
| 432 | * For sendmail users, this file is /etc/mail/trusted-users. |
| 433 | * @throws MbstringException |
| 434 | * |
| 435 | */ |
| 436 | function mb_send_mail(string $to, string $subject, string $message, $additional_headers = null, string $additional_parameter = null): void |
| 437 | { |
| 438 | error_clear_last(); |
| 439 | $result = \mb_send_mail($to, $subject, $message, $additional_headers, $additional_parameter); |
| 440 | if ($result === \false) { |
| 441 | throw MbstringException::createFromPhpError(); |
| 442 | } |
| 443 | } |
| 444 | /** |
| 445 | * |
| 446 | * |
| 447 | * @param string $pattern The regular expression pattern. |
| 448 | * @param string $string The string being split. |
| 449 | * @param int $limit |
| 450 | * @return array The result as an array. |
| 451 | * @throws MbstringException |
| 452 | * |
| 453 | */ |
| 454 | function mb_split(string $pattern, string $string, int $limit = -1): array |
| 455 | { |
| 456 | error_clear_last(); |
| 457 | $result = \mb_split($pattern, $string, $limit); |
| 458 | if ($result === \false) { |
| 459 | throw MbstringException::createFromPhpError(); |
| 460 | } |
| 461 | return $result; |
| 462 | } |
| 463 | /** |
| 464 | * This function will return an array of strings, it is a version of str_split with support for encodings of variable character size as well as fixed-size encodings of 1,2 or 4 byte characters. |
| 465 | * If the split_length parameter is specified, the string is broken down into chunks of the specified length in characters (not bytes). |
| 466 | * The encoding parameter can be optionally specified and it is good practice to do so. |
| 467 | * |
| 468 | * @param string $string The string to split into characters or chunks. |
| 469 | * @param int $split_length If specified, each element of the returned array will be composed of multiple characters instead of a single character. |
| 470 | * @param string $encoding The encoding |
| 471 | * parameter is the character encoding. If it is omitted, the internal character |
| 472 | * encoding value will be used. |
| 473 | * |
| 474 | * A string specifying one of the supported encodings. |
| 475 | * @return array mb_str_split returns an array of strings. |
| 476 | * @throws MbstringException |
| 477 | * |
| 478 | */ |
| 479 | function mb_str_split(string $string, int $split_length = 1, string $encoding = null): array |
| 480 | { |
| 481 | error_clear_last(); |
| 482 | if ($encoding !== null) { |
| 483 | $result = \mb_str_split($string, $split_length, $encoding); |
| 484 | } else { |
| 485 | $result = \mb_str_split($string, $split_length); |
| 486 | } |
| 487 | if ($result === \false) { |
| 488 | throw MbstringException::createFromPhpError(); |
| 489 | } |
| 490 | return $result; |
| 491 | } |
| 492 |