Eka
Eka

Reputation: 15010

How to isolate specific hyperlinks using simple html dom php

How to isolate specific hyperlinks from a website(using simple html dom php). for example below script were i want only the link which have the bolded path with http://www.website.com/release/...

<a class="blue" href="/releases/2012.htm">release of ---</a>
<a class="blue" href="/releases/1/2012.htm">release of ---</a>

and links which has a subdomain (news) in it

 <a class="blue" href="http://news.website.com/one/1">release of ---</a>

and also is there any way to isolate a specific link from a website and go inside that specific link and fetch its title and description

Upvotes: 1

Views: 328

Answers (2)

Another Code
Another Code

Reputation: 3151

Iterate through all links that can be a potential match, then check whether their href matches your criteria. You can do this check by using basic string functions or regular expressions if the criteria are too advanced for basic matches.

Upvotes: 1

Amber
Amber

Reputation: 526783

Normally you'd just iterate over all of the links, checking to see if each one matches your conditions, and if so, grab the data you want from it.

foreach($html->find('a') as $link) {
    if(substr($link->href, 0, 10) == "/releases/") {
        // do stuff with a releases link
    }

    // and so on
}

Upvotes: 2

Related Questions