preg_grep_basic.phpt [plain text]
--TEST--
Test preg_grep() function : basic functionality
--FILE--
<?php
$array = array('HTTP://WWW.EXAMPLE.COM', '/index.html', '/info/stat/', 'http://test.uk.com/index/html', '/display/dept.php');
var_dump($array);
var_dump(preg_grep('@^HTTP(.*?)\w{2,}$@i', $array)); var_dump(preg_grep('@(/\w+\.*/*)+@', $array)); var_dump(preg_grep('@^http://[^w]{3}.*$@i', $array)); var_dump(preg_grep('@.*?\.co\.uk$@i', $array)); var_dump(preg_grep('@^HTTP(.*?)\w{2,}$@i', $array, PREG_GREP_INVERT));
?>
--EXPECT--
array(5) {
[0]=>
string(22) "HTTP://WWW.EXAMPLE.COM"
[1]=>
string(11) "/index.html"
[2]=>
string(11) "/info/stat/"
[3]=>
string(29) "http://test.uk.com/index/html"
[4]=>
string(17) "/display/dept.php"
}
array(2) {
[0]=>
string(22) "HTTP://WWW.EXAMPLE.COM"
[3]=>
string(29) "http://test.uk.com/index/html"
}
array(5) {
[0]=>
string(22) "HTTP://WWW.EXAMPLE.COM"
[1]=>
string(11) "/index.html"
[2]=>
string(11) "/info/stat/"
[3]=>
string(29) "http://test.uk.com/index/html"
[4]=>
string(17) "/display/dept.php"
}
array(1) {
[3]=>
string(29) "http://test.uk.com/index/html"
}
array(0) {
}
array(3) {
[1]=>
string(11) "/index.html"
[2]=>
string(11) "/info/stat/"
[4]=>
string(17) "/display/dept.php"
}