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
pcre.php
655 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\PcreException; |
| 6 | /** |
| 7 | * Searches subject for all matches to the regular |
| 8 | * expression given in pattern and puts them in |
| 9 | * matches in the order specified by |
| 10 | * flags. |
| 11 | * |
| 12 | * After the first match is found, the subsequent searches are continued |
| 13 | * on from end of the last match. |
| 14 | * |
| 15 | * @param string $pattern The pattern to search for, as a string. |
| 16 | * @param string $subject The input string. |
| 17 | * @param array $matches Array of all matches in multi-dimensional array ordered according to |
| 18 | * flags. |
| 19 | * @param int $flags Can be a combination of the following flags (note that it doesn't make |
| 20 | * sense to use PREG_PATTERN_ORDER together with |
| 21 | * PREG_SET_ORDER): |
| 22 | * |
| 23 | * |
| 24 | * PREG_PATTERN_ORDER |
| 25 | * |
| 26 | * |
| 27 | * Orders results so that $matches[0] is an array of full |
| 28 | * pattern matches, $matches[1] is an array of strings matched by |
| 29 | * the first parenthesized subpattern, and so on. |
| 30 | * |
| 31 | * |
| 32 | * |
| 33 | * |
| 34 | * |
| 35 | * ]]> |
| 36 | * |
| 37 | * The above example will output: |
| 38 | * |
| 39 | * example: , this is a test |
| 40 | * example: , this is a test |
| 41 | * ]]> |
| 42 | * |
| 43 | * |
| 44 | * So, $out[0] contains array of strings that matched full pattern, |
| 45 | * and $out[1] contains array of strings enclosed by tags. |
| 46 | * |
| 47 | * |
| 48 | * |
| 49 | * |
| 50 | * If the pattern contains named subpatterns, $matches |
| 51 | * additionally contains entries for keys with the subpattern name. |
| 52 | * |
| 53 | * |
| 54 | * If the pattern contains duplicate named subpatterns, only the rightmost |
| 55 | * subpattern is stored in $matches[NAME]. |
| 56 | * |
| 57 | * |
| 58 | * |
| 59 | * ]]> |
| 60 | * |
| 61 | * The above example will output: |
| 62 | * |
| 63 | * |
| 64 | * [1] => bar |
| 65 | * ) |
| 66 | * ]]> |
| 67 | * |
| 68 | * |
| 69 | * |
| 70 | * |
| 71 | * |
| 72 | * |
| 73 | * PREG_SET_ORDER |
| 74 | * |
| 75 | * |
| 76 | * Orders results so that $matches[0] is an array of first set |
| 77 | * of matches, $matches[1] is an array of second set of matches, |
| 78 | * and so on. |
| 79 | * |
| 80 | * |
| 81 | * |
| 82 | * ]]> |
| 83 | * |
| 84 | * The above example will output: |
| 85 | * |
| 86 | * example: , example: |
| 87 | * this is a test, this is a test |
| 88 | * ]]> |
| 89 | * |
| 90 | * |
| 91 | * |
| 92 | * |
| 93 | * |
| 94 | * |
| 95 | * PREG_OFFSET_CAPTURE |
| 96 | * |
| 97 | * |
| 98 | * If this flag is passed, for every occurring match the appendant string |
| 99 | * offset (in bytes) will also be returned. Note that this changes the value of |
| 100 | * matches into an array of arrays where every element is an |
| 101 | * array consisting of the matched string at offset 0 |
| 102 | * and its string offset into subject at offset |
| 103 | * 1. |
| 104 | * |
| 105 | * |
| 106 | * |
| 107 | * ]]> |
| 108 | * |
| 109 | * The above example will output: |
| 110 | * |
| 111 | * Array |
| 112 | * ( |
| 113 | * [0] => Array |
| 114 | * ( |
| 115 | * [0] => foobarbaz |
| 116 | * [1] => 0 |
| 117 | * ) |
| 118 | * |
| 119 | * ) |
| 120 | * |
| 121 | * [1] => Array |
| 122 | * ( |
| 123 | * [0] => Array |
| 124 | * ( |
| 125 | * [0] => foo |
| 126 | * [1] => 0 |
| 127 | * ) |
| 128 | * |
| 129 | * ) |
| 130 | * |
| 131 | * [2] => Array |
| 132 | * ( |
| 133 | * [0] => Array |
| 134 | * ( |
| 135 | * [0] => bar |
| 136 | * [1] => 3 |
| 137 | * ) |
| 138 | * |
| 139 | * ) |
| 140 | * |
| 141 | * [3] => Array |
| 142 | * ( |
| 143 | * [0] => Array |
| 144 | * ( |
| 145 | * [0] => baz |
| 146 | * [1] => 6 |
| 147 | * ) |
| 148 | * |
| 149 | * ) |
| 150 | * |
| 151 | * ) |
| 152 | * ]]> |
| 153 | * |
| 154 | * |
| 155 | * |
| 156 | * |
| 157 | * |
| 158 | * |
| 159 | * PREG_UNMATCHED_AS_NULL |
| 160 | * |
| 161 | * |
| 162 | * If this flag is passed, unmatched subpatterns are reported as NULL; |
| 163 | * otherwise they are reported as an empty string. |
| 164 | * |
| 165 | * |
| 166 | * |
| 167 | * |
| 168 | * |
| 169 | * Orders results so that $matches[0] is an array of full |
| 170 | * pattern matches, $matches[1] is an array of strings matched by |
| 171 | * the first parenthesized subpattern, and so on. |
| 172 | * |
| 173 | * |
| 174 | * |
| 175 | * |
| 176 | * ]]> |
| 177 | * |
| 178 | * The above example will output: |
| 179 | * |
| 180 | * example: , this is a test |
| 181 | * example: , this is a test |
| 182 | * ]]> |
| 183 | * |
| 184 | * |
| 185 | * So, $out[0] contains array of strings that matched full pattern, |
| 186 | * and $out[1] contains array of strings enclosed by tags. |
| 187 | * |
| 188 | * |
| 189 | * |
| 190 | * The above example will output: |
| 191 | * |
| 192 | * So, $out[0] contains array of strings that matched full pattern, |
| 193 | * and $out[1] contains array of strings enclosed by tags. |
| 194 | * |
| 195 | * If the pattern contains named subpatterns, $matches |
| 196 | * additionally contains entries for keys with the subpattern name. |
| 197 | * |
| 198 | * If the pattern contains duplicate named subpatterns, only the rightmost |
| 199 | * subpattern is stored in $matches[NAME]. |
| 200 | * |
| 201 | * |
| 202 | * |
| 203 | * ]]> |
| 204 | * |
| 205 | * The above example will output: |
| 206 | * |
| 207 | * |
| 208 | * [1] => bar |
| 209 | * ) |
| 210 | * ]]> |
| 211 | * |
| 212 | * |
| 213 | * |
| 214 | * The above example will output: |
| 215 | * |
| 216 | * Orders results so that $matches[0] is an array of first set |
| 217 | * of matches, $matches[1] is an array of second set of matches, |
| 218 | * and so on. |
| 219 | * |
| 220 | * |
| 221 | * |
| 222 | * ]]> |
| 223 | * |
| 224 | * The above example will output: |
| 225 | * |
| 226 | * example: , example: |
| 227 | * this is a test, this is a test |
| 228 | * ]]> |
| 229 | * |
| 230 | * |
| 231 | * |
| 232 | * The above example will output: |
| 233 | * |
| 234 | * If this flag is passed, for every occurring match the appendant string |
| 235 | * offset (in bytes) will also be returned. Note that this changes the value of |
| 236 | * matches into an array of arrays where every element is an |
| 237 | * array consisting of the matched string at offset 0 |
| 238 | * and its string offset into subject at offset |
| 239 | * 1. |
| 240 | * |
| 241 | * |
| 242 | * |
| 243 | * ]]> |
| 244 | * |
| 245 | * The above example will output: |
| 246 | * |
| 247 | * Array |
| 248 | * ( |
| 249 | * [0] => Array |
| 250 | * ( |
| 251 | * [0] => foobarbaz |
| 252 | * [1] => 0 |
| 253 | * ) |
| 254 | * |
| 255 | * ) |
| 256 | * |
| 257 | * [1] => Array |
| 258 | * ( |
| 259 | * [0] => Array |
| 260 | * ( |
| 261 | * [0] => foo |
| 262 | * [1] => 0 |
| 263 | * ) |
| 264 | * |
| 265 | * ) |
| 266 | * |
| 267 | * [2] => Array |
| 268 | * ( |
| 269 | * [0] => Array |
| 270 | * ( |
| 271 | * [0] => bar |
| 272 | * [1] => 3 |
| 273 | * ) |
| 274 | * |
| 275 | * ) |
| 276 | * |
| 277 | * [3] => Array |
| 278 | * ( |
| 279 | * [0] => Array |
| 280 | * ( |
| 281 | * [0] => baz |
| 282 | * [1] => 6 |
| 283 | * ) |
| 284 | * |
| 285 | * ) |
| 286 | * |
| 287 | * ) |
| 288 | * ]]> |
| 289 | * |
| 290 | * |
| 291 | * |
| 292 | * The above example will output: |
| 293 | * |
| 294 | * If this flag is passed, unmatched subpatterns are reported as NULL; |
| 295 | * otherwise they are reported as an empty string. |
| 296 | * |
| 297 | * If no order flag is given, PREG_PATTERN_ORDER is |
| 298 | * assumed. |
| 299 | * @param int $offset Orders results so that $matches[0] is an array of full |
| 300 | * pattern matches, $matches[1] is an array of strings matched by |
| 301 | * the first parenthesized subpattern, and so on. |
| 302 | * |
| 303 | * |
| 304 | * |
| 305 | * |
| 306 | * ]]> |
| 307 | * |
| 308 | * The above example will output: |
| 309 | * |
| 310 | * example: , this is a test |
| 311 | * example: , this is a test |
| 312 | * ]]> |
| 313 | * |
| 314 | * |
| 315 | * So, $out[0] contains array of strings that matched full pattern, |
| 316 | * and $out[1] contains array of strings enclosed by tags. |
| 317 | * |
| 318 | * |
| 319 | * |
| 320 | * The above example will output: |
| 321 | * |
| 322 | * So, $out[0] contains array of strings that matched full pattern, |
| 323 | * and $out[1] contains array of strings enclosed by tags. |
| 324 | * |
| 325 | * If the pattern contains named subpatterns, $matches |
| 326 | * additionally contains entries for keys with the subpattern name. |
| 327 | * |
| 328 | * If the pattern contains duplicate named subpatterns, only the rightmost |
| 329 | * subpattern is stored in $matches[NAME]. |
| 330 | * |
| 331 | * |
| 332 | * |
| 333 | * ]]> |
| 334 | * |
| 335 | * The above example will output: |
| 336 | * |
| 337 | * |
| 338 | * [1] => bar |
| 339 | * ) |
| 340 | * ]]> |
| 341 | * |
| 342 | * |
| 343 | * |
| 344 | * The above example will output: |
| 345 | * @return int Returns the number of full pattern matches (which might be zero). |
| 346 | * @throws PcreException |
| 347 | * |
| 348 | */ |
| 349 | function preg_match_all(string $pattern, string $subject, array &$matches = null, int $flags = \PREG_PATTERN_ORDER, int $offset = 0): int |
| 350 | { |
| 351 | error_clear_last(); |
| 352 | $result = \preg_match_all($pattern, $subject, $matches, $flags, $offset); |
| 353 | if ($result === \false) { |
| 354 | throw PcreException::createFromPhpError(); |
| 355 | } |
| 356 | return $result; |
| 357 | } |
| 358 | /** |
| 359 | * Searches subject for a match to the regular |
| 360 | * expression given in pattern. |
| 361 | * |
| 362 | * @param string $pattern The pattern to search for, as a string. |
| 363 | * @param string $subject The input string. |
| 364 | * @param array $matches If matches is provided, then it is filled with |
| 365 | * the results of search. $matches[0] will contain the |
| 366 | * text that matched the full pattern, $matches[1] |
| 367 | * will have the text that matched the first captured parenthesized |
| 368 | * subpattern, and so on. |
| 369 | * @param int $flags flags can be a combination of the following flags: |
| 370 | * |
| 371 | * |
| 372 | * PREG_OFFSET_CAPTURE |
| 373 | * |
| 374 | * |
| 375 | * If this flag is passed, for every occurring match the appendant string |
| 376 | * offset (in bytes) will also be returned. Note that this changes the value of |
| 377 | * matches into an array where every element is an |
| 378 | * array consisting of the matched string at offset 0 |
| 379 | * and its string offset into subject at offset |
| 380 | * 1. |
| 381 | * |
| 382 | * |
| 383 | * |
| 384 | * ]]> |
| 385 | * |
| 386 | * The above example will output: |
| 387 | * |
| 388 | * Array |
| 389 | * ( |
| 390 | * [0] => foobarbaz |
| 391 | * [1] => 0 |
| 392 | * ) |
| 393 | * |
| 394 | * [1] => Array |
| 395 | * ( |
| 396 | * [0] => foo |
| 397 | * [1] => 0 |
| 398 | * ) |
| 399 | * |
| 400 | * [2] => Array |
| 401 | * ( |
| 402 | * [0] => bar |
| 403 | * [1] => 3 |
| 404 | * ) |
| 405 | * |
| 406 | * [3] => Array |
| 407 | * ( |
| 408 | * [0] => baz |
| 409 | * [1] => 6 |
| 410 | * ) |
| 411 | * |
| 412 | * ) |
| 413 | * ]]> |
| 414 | * |
| 415 | * |
| 416 | * |
| 417 | * |
| 418 | * |
| 419 | * |
| 420 | * PREG_UNMATCHED_AS_NULL |
| 421 | * |
| 422 | * |
| 423 | * If this flag is passed, unmatched subpatterns are reported as NULL; |
| 424 | * otherwise they are reported as an empty string. |
| 425 | * |
| 426 | * |
| 427 | * |
| 428 | * ]]> |
| 429 | * |
| 430 | * The above example will output: |
| 431 | * |
| 432 | * |
| 433 | * string(2) "ac" |
| 434 | * [1]=> |
| 435 | * string(1) "a" |
| 436 | * [2]=> |
| 437 | * string(0) "" |
| 438 | * [3]=> |
| 439 | * string(1) "c" |
| 440 | * } |
| 441 | * array(4) { |
| 442 | * [0]=> |
| 443 | * string(2) "ac" |
| 444 | * [1]=> |
| 445 | * string(1) "a" |
| 446 | * [2]=> |
| 447 | * NULL |
| 448 | * [3]=> |
| 449 | * string(1) "c" |
| 450 | * } |
| 451 | * ]]> |
| 452 | * |
| 453 | * |
| 454 | * |
| 455 | * |
| 456 | * |
| 457 | * |
| 458 | * |
| 459 | * If this flag is passed, for every occurring match the appendant string |
| 460 | * offset (in bytes) will also be returned. Note that this changes the value of |
| 461 | * matches into an array where every element is an |
| 462 | * array consisting of the matched string at offset 0 |
| 463 | * and its string offset into subject at offset |
| 464 | * 1. |
| 465 | * |
| 466 | * |
| 467 | * |
| 468 | * ]]> |
| 469 | * |
| 470 | * The above example will output: |
| 471 | * |
| 472 | * Array |
| 473 | * ( |
| 474 | * [0] => foobarbaz |
| 475 | * [1] => 0 |
| 476 | * ) |
| 477 | * |
| 478 | * [1] => Array |
| 479 | * ( |
| 480 | * [0] => foo |
| 481 | * [1] => 0 |
| 482 | * ) |
| 483 | * |
| 484 | * [2] => Array |
| 485 | * ( |
| 486 | * [0] => bar |
| 487 | * [1] => 3 |
| 488 | * ) |
| 489 | * |
| 490 | * [3] => Array |
| 491 | * ( |
| 492 | * [0] => baz |
| 493 | * [1] => 6 |
| 494 | * ) |
| 495 | * |
| 496 | * ) |
| 497 | * ]]> |
| 498 | * |
| 499 | * |
| 500 | * |
| 501 | * The above example will output: |
| 502 | * |
| 503 | * If this flag is passed, unmatched subpatterns are reported as NULL; |
| 504 | * otherwise they are reported as an empty string. |
| 505 | * |
| 506 | * |
| 507 | * |
| 508 | * ]]> |
| 509 | * |
| 510 | * The above example will output: |
| 511 | * |
| 512 | * |
| 513 | * string(2) "ac" |
| 514 | * [1]=> |
| 515 | * string(1) "a" |
| 516 | * [2]=> |
| 517 | * string(0) "" |
| 518 | * [3]=> |
| 519 | * string(1) "c" |
| 520 | * } |
| 521 | * array(4) { |
| 522 | * [0]=> |
| 523 | * string(2) "ac" |
| 524 | * [1]=> |
| 525 | * string(1) "a" |
| 526 | * [2]=> |
| 527 | * NULL |
| 528 | * [3]=> |
| 529 | * string(1) "c" |
| 530 | * } |
| 531 | * ]]> |
| 532 | * |
| 533 | * |
| 534 | * |
| 535 | * The above example will output: |
| 536 | * @param int $offset If this flag is passed, for every occurring match the appendant string |
| 537 | * offset (in bytes) will also be returned. Note that this changes the value of |
| 538 | * matches into an array where every element is an |
| 539 | * array consisting of the matched string at offset 0 |
| 540 | * and its string offset into subject at offset |
| 541 | * 1. |
| 542 | * |
| 543 | * |
| 544 | * |
| 545 | * ]]> |
| 546 | * |
| 547 | * The above example will output: |
| 548 | * |
| 549 | * Array |
| 550 | * ( |
| 551 | * [0] => foobarbaz |
| 552 | * [1] => 0 |
| 553 | * ) |
| 554 | * |
| 555 | * [1] => Array |
| 556 | * ( |
| 557 | * [0] => foo |
| 558 | * [1] => 0 |
| 559 | * ) |
| 560 | * |
| 561 | * [2] => Array |
| 562 | * ( |
| 563 | * [0] => bar |
| 564 | * [1] => 3 |
| 565 | * ) |
| 566 | * |
| 567 | * [3] => Array |
| 568 | * ( |
| 569 | * [0] => baz |
| 570 | * [1] => 6 |
| 571 | * ) |
| 572 | * |
| 573 | * ) |
| 574 | * ]]> |
| 575 | * |
| 576 | * |
| 577 | * |
| 578 | * The above example will output: |
| 579 | * @return int preg_match returns 1 if the pattern |
| 580 | * matches given subject, 0 if it does not. |
| 581 | * @throws PcreException |
| 582 | * |
| 583 | */ |
| 584 | function preg_match(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int |
| 585 | { |
| 586 | error_clear_last(); |
| 587 | $result = \preg_match($pattern, $subject, $matches, $flags, $offset); |
| 588 | if ($result === \false) { |
| 589 | throw PcreException::createFromPhpError(); |
| 590 | } |
| 591 | return $result; |
| 592 | } |
| 593 | /** |
| 594 | * Split the given string by a regular expression. |
| 595 | * |
| 596 | * @param string $pattern The pattern to search for, as a string. |
| 597 | * @param string $subject The input string. |
| 598 | * @param int|null $limit If specified, then only substrings up to limit |
| 599 | * are returned with the rest of the string being placed in the last |
| 600 | * substring. A limit of -1 or 0 means "no limit". |
| 601 | * @param int $flags flags can be any combination of the following |
| 602 | * flags (combined with the | bitwise operator): |
| 603 | * |
| 604 | * |
| 605 | * PREG_SPLIT_NO_EMPTY |
| 606 | * |
| 607 | * |
| 608 | * If this flag is set, only non-empty pieces will be returned by |
| 609 | * preg_split. |
| 610 | * |
| 611 | * |
| 612 | * |
| 613 | * |
| 614 | * PREG_SPLIT_DELIM_CAPTURE |
| 615 | * |
| 616 | * |
| 617 | * If this flag is set, parenthesized expression in the delimiter pattern |
| 618 | * will be captured and returned as well. |
| 619 | * |
| 620 | * |
| 621 | * |
| 622 | * |
| 623 | * PREG_SPLIT_OFFSET_CAPTURE |
| 624 | * |
| 625 | * |
| 626 | * If this flag is set, for every occurring match the appendant string |
| 627 | * offset will also be returned. Note that this changes the return |
| 628 | * value in an array where every element is an array consisting of the |
| 629 | * matched string at offset 0 and its string offset |
| 630 | * into subject at offset 1. |
| 631 | * |
| 632 | * |
| 633 | * |
| 634 | * |
| 635 | * |
| 636 | * If this flag is set, for every occurring match the appendant string |
| 637 | * offset will also be returned. Note that this changes the return |
| 638 | * value in an array where every element is an array consisting of the |
| 639 | * matched string at offset 0 and its string offset |
| 640 | * into subject at offset 1. |
| 641 | * @return array Returns an array containing substrings of subject |
| 642 | * split along boundaries matched by pattern. |
| 643 | * @throws PcreException |
| 644 | * |
| 645 | */ |
| 646 | function preg_split(string $pattern, string $subject, ?int $limit = -1, int $flags = 0): array |
| 647 | { |
| 648 | error_clear_last(); |
| 649 | $result = \preg_split($pattern, $subject, $limit, $flags); |
| 650 | if ($result === \false) { |
| 651 | throw PcreException::createFromPhpError(); |
| 652 | } |
| 653 | return $result; |
| 654 | } |
| 655 |