user2098185
user2098185

Reputation:

PHP Simple HTML DOM Parser function to parse(get anchore tag) from html source

I need to find a way to request the href & value of all <a elements from HTML file.

For example:

<a href="http://domain.com" class="clsLink">Domain Link</a>
Output:

href: 'http://domain.com'
value: 'Domain Link'

Upvotes: 0

Views: 1570

Answers (1)

RavatSinh Sisodiya
RavatSinh Sisodiya

Reputation: 1608

Try this code.

$html=file_get_html($url);
foreach ($html->find('a') as $links){

    //Get link text
    echo $links->innertext;

    //Get href value
    echo $links->href;
}

Upvotes: 1

Related Questions