简体   繁体   English

当我只有div的名称时,php简单的html dom href

[英]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! 希望这个能对您有所帮助!

我怎么找到最后一个<div class>在带有 PHP 简单 HTML DOM 解析器的 HTML 文件中?</div><div id="text_translate"><p> 根据<a href="http://simplehtmldom.sourceforge.net/" rel="nofollow noreferrer">SIMPLE HTML DOM PARSER</a>的文档(在“How to modify HTML Elements”选项卡下),这段代码找到了<div class="hello">的第一个实例:</p><pre> $html = str_get_html('<div class="hello">Hello</div><div class="world">World</div>'); $html->find('div[class=hello]', 0)->innertext = 'foo'; echo $html; // Output: <div class="hello">foo</div><div class="world">World</div></pre><p> 如果我想在<div class="hello">的<em>最后一个</em>实例中插入 'foo' 怎么办,假设 HTML 代码有很多<div class="hello">实例。</p><p> 什么应该取代0 ?</p></div> - How do I find the last <div class> in an HTML File with PHP Simple HTML DOM Parser?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 php简单的html dom在td中获取href id - php simple html dom get a href id inside td PHP简单HTML DOM解析器- <body> 仅重命名为div ID - PHP Simple HTML DOM Parser - <body> only with a rename of a div ID 我怎么找到这个div? (PHP Simple HTML DOM Parser) - How do I find this div ? (PHP Simple HTML DOM Parser) PHP + 简单的 HTML DOM:选择一个带有类的 div 内的标签,在另一个带有类的 div 内 - PHP + Simple HTML DOM: Select a tag inside a div with class inside another div with class PHP简单HTML DOM解析器div选择器 - PHP Simple HTML DOM Parser div selector HTML div中的href = php变量 - a href = php variable inside html div PHP简单HTML DOM解析器-仅精确来自div的某些信息 - PHP Simple HTML DOM Parser - exact only certain info from a div 通过PHP中的simple_html_dom解析HTML时,如何区分单个Div中的标签 - How to differentiate tags in single Div when parsing HTML via simple_html_dom in PHP PHP简单HTML DOM解析器,在没有类或id的标记内查找文本 - PHP Simple HTML DOM Parser, find text inside tags that have no class nor id 我怎么找到最后一个<div class>在带有 PHP 简单 HTML DOM 解析器的 HTML 文件中?</div><div id="text_translate"><p> 根据<a href="http://simplehtmldom.sourceforge.net/" rel="nofollow noreferrer">SIMPLE HTML DOM PARSER</a>的文档(在“How to modify HTML Elements”选项卡下),这段代码找到了<div class="hello">的第一个实例:</p><pre> $html = str_get_html('<div class="hello">Hello</div><div class="world">World</div>'); $html->find('div[class=hello]', 0)->innertext = 'foo'; echo $html; // Output: <div class="hello">foo</div><div class="world">World</div></pre><p> 如果我想在<div class="hello">的<em>最后一个</em>实例中插入 'foo' 怎么办,假设 HTML 代码有很多<div class="hello">实例。</p><p> 什么应该取代0 ?</p></div> - How do I find the last <div class> in an HTML File with PHP Simple HTML DOM Parser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM