简体   繁体   中英

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. I know how to get to the href if it was inside the div but not this way around. 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() :

$div = $doc->find('.CountryRiskReportLink', 0);
echo $div->parent()->href;

Yes, You can get the value of href attribute without JQuery. 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM