【问题标题】:How to get the attribute value of an html tag using simpleHTMLDom?如何使用 simpleHTMLDom 获取 html 标签的属性值?
【发布时间】:2016-03-23 07:56:58
【问题描述】:

我想获取一个属性的内容,例如:<a href="#" title="theTitle" class="foo"></a> 如何解析和获取"theTitle"

foreach($html->find('div[class=foo]') as $ClassContent)

这给出了我知道的<div> 的内容,但是有什么方法可以得到theTitle 吗?

谢谢大家。

【问题讨论】:

    标签: simple-html-dom


    【解决方案1】:

    试试这个:

    $(".foo").attr("title");
    

    【讨论】:

    • 有什么方法可以使用 php 来执行它?
    【解决方案2】:

    知道了,明文给出标签之间的文本

    对于:<a href='#' class="foo" title='TheTitleToGet'></a> 获取title 内容:

    foreach($html->find('div[class=foo]') as $getTitle){
            $title = array();
            $title [] = $getTitle->title;
    }
    

    这将获取写入属性title 内的所有标题。如果你想要 src<img src="someSRC"> 一样,只做 img[] = $getImgSRC->src

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      相关资源
      最近更新 更多