1--TEST-- 2abusing pcre 3--FILE-- 4<?php 5 6var_dump(preg_match_all('/((?:(?:unsigned|struct)\s+)?\w+)(?:\s*(\*+)\s+|\s+(\**))(\w+(?:\[\s*\w*\s*\])?)\s*(?:(=)[^,;]+)?((?:\s*,\s*\**\s*\w+(?:\[\s*\w*\s*\])?\s*(?:=[^,;]+)?)*)\s*;/S', 'unsigned int xpto = 124; short a, b;', $m, PREG_SET_ORDER)); 7var_dump($m); 8 9var_dump(preg_match_all('/(?:\([^)]+\))?(&?)([\w>.()-]+(?:\[\w+\])?)\s*,?((?:\)*\s*=)?)/S', '&a, b, &c', $m, PREG_SET_ORDER)); 10var_dump($m); 11 12var_dump(preg_match_all('/zend_parse_parameters(?:_ex\s*\([^,]+,[^,]+|\s*\([^,]+),\s*"([^"]*)"\s*,\s*([^{;]*)/S', 'zend_parse_parameters( 0, "addd|s/", a, b, &c);', $m, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)); 13var_dump($m); 14 15var_dump(preg_replace(array('@//.*@S', '@/\*.*\*/@SsUe'), array('', 'preg_replace("/[^\r\n]+/S", "", \'$0\')'), "hello\n//x \n/*\ns\n*/")); 16 17var_dump(preg_split('/PHP_(?:NAMED_)?(?:FUNCTION|METHOD)\s*\((\w+(?:,\s*\w+)?)\)/S', "PHP_FUNCTION(s, preg_match)\n{\nlalala", -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE)); 18?> 19--EXPECTF-- 20int(2) 21array(2) { 22 [0]=> 23 array(7) { 24 [0]=> 25 string(24) "unsigned int xpto = 124;" 26 [1]=> 27 string(12) "unsigned int" 28 [2]=> 29 string(0) "" 30 [3]=> 31 string(0) "" 32 [4]=> 33 string(4) "xpto" 34 [5]=> 35 string(1) "=" 36 [6]=> 37 string(0) "" 38 } 39 [1]=> 40 array(7) { 41 [0]=> 42 string(11) "short a, b;" 43 [1]=> 44 string(5) "short" 45 [2]=> 46 string(0) "" 47 [3]=> 48 string(0) "" 49 [4]=> 50 string(1) "a" 51 [5]=> 52 string(0) "" 53 [6]=> 54 string(3) ", b" 55 } 56} 57int(3) 58array(3) { 59 [0]=> 60 array(4) { 61 [0]=> 62 string(3) "&a," 63 [1]=> 64 string(1) "&" 65 [2]=> 66 string(1) "a" 67 [3]=> 68 string(0) "" 69 } 70 [1]=> 71 array(4) { 72 [0]=> 73 string(2) "b," 74 [1]=> 75 string(0) "" 76 [2]=> 77 string(1) "b" 78 [3]=> 79 string(0) "" 80 } 81 [2]=> 82 array(4) { 83 [0]=> 84 string(2) "&c" 85 [1]=> 86 string(1) "&" 87 [2]=> 88 string(1) "c" 89 [3]=> 90 string(0) "" 91 } 92} 93int(1) 94array(1) { 95 [0]=> 96 array(3) { 97 [0]=> 98 array(2) { 99 [0]=> 100 string(46) "zend_parse_parameters( 0, "addd|s/", a, b, &c)" 101 [1]=> 102 int(0) 103 } 104 [1]=> 105 array(2) { 106 [0]=> 107 string(7) "addd|s/" 108 [1]=> 109 int(27) 110 } 111 [2]=> 112 array(2) { 113 [0]=> 114 string(9) "a, b, &c)" 115 [1]=> 116 int(37) 117 } 118 } 119} 120 121Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in %s on line %d 122string(9) "hello 123 124 125 126" 127array(3) { 128 [0]=> 129 array(2) { 130 [0]=> 131 string(0) "" 132 [1]=> 133 int(0) 134 } 135 [1]=> 136 array(2) { 137 [0]=> 138 string(13) "s, preg_match" 139 [1]=> 140 int(13) 141 } 142 [2]=> 143 array(2) { 144 [0]=> 145 string(9) " 146{ 147lalala" 148 [1]=> 149 int(27) 150 } 151} 152