<?php
$list = "http://www.example.com/example1/
http://www.example.com/example2/
http://www.example.com/example3/
http://www.example.com/example4/
http://www.example.com/example.js
http://www.example.com/example.css
http://www.example.com/example1.js?v=123
http://www.example.com/{path}
http://www.example.com/feed/
http://www.example.com/?p=66";
$arr = preg_split("/[\r\n]+/",$list);
// check our input array
print_r($arr);
$map = array();
foreach($arr as $v){
if(!preg_match("/({path}|\.(js|css)|\?p=\d+|\/feed\/)$/",$v)){
$map[] = $v;
}
};
// check our output array
print_r($map);
?>
{path}
これは、または.css
または.js
または?p=##
(# は数字) または で終わらない URL に一致させることを前提としています/feed/
。/example1.js?v=123
これが、一致するものが依然として存在する理由です。末尾だけでなく、文字列の任意の場所に一致させるに$
は、正規表現の末尾 (単語 の直後feed
) から を削除します。
私のコンソール出力:
Array
(
[0] => http://www.example.com/example1/
[1] => http://www.example.com/example2/
[2] => http://www.example.com/example3/
[3] => http://www.example.com/example4/
[4] => http://www.example.com/example.js
[5] => http://www.example.com/example.css
[6] => http://www.example.com/example1.js?v=123
[7] => http://www.example.com/{path}
[8] => http://www.example.com/feed/
[9] => http://www.example.com/?p=66
)
Array
(
[0] => http://www.example.com/example1/
[1] => http://www.example.com/example2/
[2] => http://www.example.com/example3/
[3] => http://www.example.com/example4/
[4] => http://www.example.com/example1.js?v=123
)