1--TEST-- 2Test preg_match_all() function : basic functionality 3--FILE-- 4<?php 5$string = 'Hello, world! This is a test. This is another test. \[4]. 34534 string.'; 6 7var_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) 8var_dump($match1); 9 10var_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) 11var_dump($match2); 12 13var_dump(preg_match_all('@\. \\\(.*).@', $string, $match3, PREG_PATTERN_ORDER)); //finds ".\ [...]" and everything else to the end of the string. (greedy) (1 match) 14var_dump($match3); 15 16var_dump(preg_match_all('/\d{2}$/', $string, $match4)); //tries to find 2 digits at the end of a string (0 matches) 17var_dump($match4); 18 19var_dump(preg_match_all('/(This is a ){2}(.*)\stest/', $string, $match5)); //tries to find "This is aThis is a [...] test" (0 matches) 20var_dump($match5); 21?> 22--EXPECT-- 23int(1) 24array(1) { 25 [0]=> 26 array(1) { 27 [0]=> 28 array(2) { 29 [0]=> 30 string(1) "3" 31 [1]=> 32 int(61) 33 } 34 } 35} 36int(2) 37array(2) { 38 [0]=> 39 array(2) { 40 [0]=> 41 string(15) "This is a test." 42 [1]=> 43 string(5) " test" 44 } 45 [1]=> 46 array(2) { 47 [0]=> 48 string(21) "This is another test." 49 [1]=> 50 string(11) "nother test" 51 } 52} 53int(1) 54array(2) { 55 [0]=> 56 array(1) { 57 [0]=> 58 string(21) ". \[4]. 34534 string." 59 } 60 [1]=> 61 array(1) { 62 [0]=> 63 string(17) "[4]. 34534 string" 64 } 65} 66int(0) 67array(1) { 68 [0]=> 69 array(0) { 70 } 71} 72int(0) 73array(3) { 74 [0]=> 75 array(0) { 76 } 77 [1]=> 78 array(0) { 79 } 80 [2]=> 81 array(0) { 82 } 83} 84