Reputation: 25
I have a html string
<html>
<head></head>
<body>
bla bla bla <br />
<a id="downloadbutton" href ="http://tomtuoi.com/file.exe";
</body>
</html>
With php dom I want get http://tomtuoi.com/file.exe url by id. thank for help
Upvotes: 1
Views: 2113
Reputation: 68556
Do like this..
<?php
$html='<html>
<head></head>
<body>
bla bla bla <br />
<a id="downloadbutton" href ="http://tomtuoi.com/file.exe";
</body>
</html>';
$dom = new DOMDocument;
@$dom->loadHTML($html);
foreach ($dom->getElementsByTagName('a') as $tag) {
echo $tag->getAttribute('href'); //"prints" http://tomtuoi.com/file.exe
}
Upvotes: 2