[英]php simple html dom href when i only have name of div inside it
Hey guys so i am trying to get to the link in the code below however the only div with a name is inside the href. 大家好,我想尝试进入下面代码中的链接,但是唯一带有名称的div是在href内。 I know how to get to the href if it was inside the div but not this way around.
我知道如何到达href,如果它在div内,但不是这样。 Can anyone help?
有人可以帮忙吗?
<div>
<a href="/economic-research/blog/EconomicPublications/algeria-country-report-mar17.pdf">
<div class="CountryRiskReportLink">
Algeria Country Report
</div></a>
</div>
In simple-html-dom you would use parent()
: 在simple-html-dom中,您可以使用
parent()
:
$div = $doc->find('.CountryRiskReportLink', 0);
echo $div->parent()->href;
Yes, You can get the value of href attribute without JQuery. 是的,您可以在没有JQuery的情况下获取href属性的值。 Here is the simple snippet.
这是简单的代码段。 Try this,
尝试这个,
$a = new SimpleXMLElement("<a href='/economic-research/blog/EconomicPublications/algeria-country-report-mar17.pdf'>
<div class='CountryRiskReportLink'>
Algeria Country Report
</div>
</a>");
echo $a['href']; // will echo /economic-research/blog/EconomicPublications/algeria-country-report-mar17.pdf
die();
Hope this will help you! 希望这个能对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.