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