0

I have following code which extracts all the hyperlinks(urls) from the given web url.

<?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>";
}
?>

The above code extracts all the hyperlinks but I want to extract only links which has following pattern.

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

I know that this can be done using regular expressions but how exactly that I don't know. Please give example so I can easily understand.

1 Answer 1

0

try

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

take a look at

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

and

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.