Annotation of embedaddon/php/ext/pcre/tests/preg_grep_basic.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test preg_grep() function : basic functionality 
                      3: --FILE--
                      4: <?php
                      5: /*
                      6: * proto array preg_grep(string regex, array input [, int flags])
                      7: * Function is implemented in ext/pcre/php_pcre.c
                      8: */
                      9: $array = array('HTTP://WWW.EXAMPLE.COM', '/index.html', '/info/stat/', 'http://test.uk.com/index/html', '/display/dept.php');
                     10: var_dump($array);
                     11: var_dump(preg_grep('@^HTTP(.*?)\w{2,}$@i', $array)); //finds a string starting with http (regardless of case) (matches two)
                     12: var_dump(preg_grep('@(/\w+\.*/*)+@', $array)); //finds / followed by one or more of a-z, A-Z and 0-9, followed by zero or more . followed by zero or more / all more than once. (matches all)
                     13: var_dump(preg_grep('@^http://[^w]{3}.*$@i', $array)); //finds http:// (at the beginning of a string) not followed by 3 characters that aren't w's then anything to the end of the sttring (matches one)
                     14: var_dump(preg_grep('@.*?\.co\.uk$@i', $array)); //finds any address ending in .co.uk (matches none)
                     15: var_dump(preg_grep('@^HTTP(.*?)\w{2,}$@i', $array, PREG_GREP_INVERT)); //same as first example but the array created contains everything that is NOT matched but the regex (matches three)
                     16: 
                     17: ?>
                     18: --EXPECT--
                     19: array(5) {
                     20:   [0]=>
                     21:   string(22) "HTTP://WWW.EXAMPLE.COM"
                     22:   [1]=>
                     23:   string(11) "/index.html"
                     24:   [2]=>
                     25:   string(11) "/info/stat/"
                     26:   [3]=>
                     27:   string(29) "http://test.uk.com/index/html"
                     28:   [4]=>
                     29:   string(17) "/display/dept.php"
                     30: }
                     31: array(2) {
                     32:   [0]=>
                     33:   string(22) "HTTP://WWW.EXAMPLE.COM"
                     34:   [3]=>
                     35:   string(29) "http://test.uk.com/index/html"
                     36: }
                     37: array(5) {
                     38:   [0]=>
                     39:   string(22) "HTTP://WWW.EXAMPLE.COM"
                     40:   [1]=>
                     41:   string(11) "/index.html"
                     42:   [2]=>
                     43:   string(11) "/info/stat/"
                     44:   [3]=>
                     45:   string(29) "http://test.uk.com/index/html"
                     46:   [4]=>
                     47:   string(17) "/display/dept.php"
                     48: }
                     49: array(1) {
                     50:   [3]=>
                     51:   string(29) "http://test.uk.com/index/html"
                     52: }
                     53: array(0) {
                     54: }
                     55: array(3) {
                     56:   [1]=>
                     57:   string(11) "/index.html"
                     58:   [2]=>
                     59:   string(11) "/info/stat/"
                     60:   [4]=>
                     61:   string(17) "/display/dept.php"
                     62: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>