Annotation of embedaddon/php/ext/pcre/tests/preg_match_all_basic.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test preg_match_all() function : basic functionality
! 3: --FILE--
! 4: <?php
! 5: /*
! 6: * proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
! 7: * Function is implemented in ext/pcre/php_pcre.c
! 8: */
! 9: $string = 'Hello, world! This is a test. This is another test. \[4]. 34534 string.';
! 10: var_dump(preg_match_all('/[0-35-9]/', $string, $match1, PREG_OFFSET_CAPTURE|PREG_PATTERN_ORDER, -10)); //finds any digit that's not 4 10 digits from the end(1 match)
! 11: var_dump($match1);
! 12: var_dump(preg_match_all('/[tT]his is a(.*?)\./', $string, $match2, PREG_SET_ORDER)); //finds "This is a test." and "This is another test." (non-greedy) (2 matches)
! 13: var_dump($match2);
! 14: var_dump(preg_match_all('@\. \\\(.*).@', $string, $match3, PREG_PATTERN_ORDER)); //finds ".\ [...]" and everything else to the end of the string. (greedy) (1 match)
! 15: var_dump($match3);
! 16: var_dump(preg_match_all('/\d{2}$/', $string, $match4)); //tries to find 2 digits at the end of a string (0 matches)
! 17: var_dump($match4);
! 18: var_dump(preg_match_all('/(This is a ){2}(.*)\stest/', $string, $match5)); //tries to find "This is aThis is a [...] test" (0 matches)
! 19: var_dump($match5);
! 20: ?>
! 21: --EXPECTF--
! 22: int(1)
! 23: array(1) {
! 24: [0]=>
! 25: array(1) {
! 26: [0]=>
! 27: array(2) {
! 28: [0]=>
! 29: string(1) "3"
! 30: [1]=>
! 31: int(61)
! 32: }
! 33: }
! 34: }
! 35: int(2)
! 36: array(2) {
! 37: [0]=>
! 38: array(2) {
! 39: [0]=>
! 40: string(15) "This is a test."
! 41: [1]=>
! 42: string(5) " test"
! 43: }
! 44: [1]=>
! 45: array(2) {
! 46: [0]=>
! 47: string(21) "This is another test."
! 48: [1]=>
! 49: string(11) "nother test"
! 50: }
! 51: }
! 52: int(1)
! 53: array(2) {
! 54: [0]=>
! 55: array(1) {
! 56: [0]=>
! 57: string(21) ". \[4]. 34534 string."
! 58: }
! 59: [1]=>
! 60: array(1) {
! 61: [0]=>
! 62: string(17) "[4]. 34534 string"
! 63: }
! 64: }
! 65: int(0)
! 66: array(1) {
! 67: [0]=>
! 68: array(0) {
! 69: }
! 70: }
! 71: int(0)
! 72: array(3) {
! 73: [0]=>
! 74: array(0) {
! 75: }
! 76: [1]=>
! 77: array(0) {
! 78: }
! 79: [2]=>
! 80: array(0) {
! 81: }
! 82: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>