您好我想从HTML内容中获取Div的属性值而不使用PHP中的DOMDocument。这是我的代码:
public int compareTo(Item it) {
return Float.compare(similarity, it.similarity);
}
预计输出
<?php
$html = <<<HTML
<div class='viewBuyButt' onclick="javascript:window.location='https://somelink.com?sdf=fhasldfss';return false;"></div>
HTML;
?>
我尝试过:
https://somelink.com?sdf=fhasldfss
任何帮助将不胜感激。
答案 0 :(得分:1)
试试这个:
$html = <<<HTML
<div class='viewBuyButt' onclick="javascript:window.location='https://1.com';return false;"></div>
<div class='No-viewBuyButt' onclick="javascript:window.location='https://mahdiy.ir';return false;"></div>
<div class='viewBuyButt' >onclick="javascript:window.location='https://2.com';return false;"></div>
<div class='viewBuyButt' onclick="javascript:window.location='http://3.com';return false;"></div>
HTML;
preg_match_all("/class='viewBuyButt'((?!(\>|\<)).)*location='(.*)'/", $html, $viewAllLink);
print_r( $viewAllLink );