我正在使用此代码
<?PHP
ini_set('user_agent', 'NameOfAgent (http://www.example.net)');
$url = "http://www.example.net/somepage.html";
if(robots_allowed($url, "NameOfAgent")) {
$input = @file_get_contents($url) or die("Could not access file: $url");
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
echo $match[2];
}
}
} else {
die('Access denied by robots.txt');
}
?>
回显html页面中的所有链接地址。
是否有人知道如何修改此代码,以便代码仅列出以"sub/"
开头并以/files/a.html
结尾的链接。