这是我的数组输出:
Array
(
[0] => http://www.example.com/some-page/
[1] => http://www.example.com/another-page/
[2] => http://www.example.com/third-page/
[3] => https://www.example.com/ssl/
[4] => https://www.example.com/with-slash-at-the-end/
[5] => https://www.example.com/without-slash-at-the-end
[6] => /internal-link
[7] => /anther-internal-link/
[8] => https://www.my-own-domain.com/internal-link-too-but-with-absolute-path/
)
如何从此阵列中仅获取外部链接和内部链接?我并不重要。
答案 0 :(得分:1)
这个正则表达式似乎可以很好地找到internal link
(.*my-own-domain\.com.*)|(^\/.*$)
<强> Regex Demo 强>
PHP代码
$re = "/(?:.*my-own-domain\\.com.*)|(?:^\\/.*$)/m";
foreach($str as $x) {
if (preg_match($re, $x)) {
echo $x . "" . "\n";
}
}
<强> Ideone Demo 强>