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

StackOverflow https://stackoverflow.com/questions/15407796

  •  23-03-2022
  •  | 
  •  

문제

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'
도움이 되었습니까?

해결책

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top