simplehtmldom URL提取和匹配模式

时间:2012-06-12 05:42:10

标签: php simple-html-dom

我有以下代码,它从给定的网址中提取所有超链接(网址)。

<?php include "simple_html_dom.php";

$html=new simple_html_dom();
$html->load_file('http://www.indiastudychannel.com/colleges');
$links=$html->find('a');

foreach($links as $l)
{

    $path='http://www.indiastudychannel.com/colleges'.$l->href;
    //doScrape($path);
    echo $path."<br>";
}
?>

以上代码提取所有超链接,但我只想提取具有以下模式的链接。

http://www.indiastudychannel.com/colleges/54499-Godavari-College-Nursing.aspx http://www.indiastudychannel.com/colleges/54489-Rvs-College-Arts-And-Science.aspx http://www.indiastudychannel.com/colleges/54488-Sankara-Institute-Management.aspx

我知道这可以使用正则表达式来完成,但我究竟是多么不知道。请举例让我很容易理解。

1 个答案:

答案 0 :(得分:0)

preg_match("/^http://www.indiastudychannel.com/colleges/54489/\");

看看

http://php.net/manual/en/function.preg-match.php

http://weblogtoolscollection.com/regex/regex.php