我有一个html字符串
<html>
<head></head>
<body>
bla bla bla <br />
<a id="downloadbutton" href ="http://tomtuoi.com/file.exe";
</body>
</html>
使用php dom我希望通过id获取http://tomtuoi.com/file.exe url。感谢您的帮助
答案 0 :(得分:2)
这样做..
<?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
}