【问题标题】:PHP Attribute for innerhtml [duplicate]innerhtml的PHP属性[重复]
【发布时间】:2018-06-15 13:41:58
【问题描述】:

有没有办法通过 PHP 中的 getAttribute 选择 innerHTML。 我已经尝试过了,但它不起作用:

$fetchresult[] = array($link->getAttribute("innerhtml"), $link->nodeValue);

当我 var_dump $link 这是输出:

object(DOMElement)#7 (18) { ["tagName"]=> string(3) "div" 
["schemaTypeInfo"]=> NULL ["nodeName"]=> string(3) "div" ["nodeValue"]=> 
string(24) "TEXT" ["nodeType"]=> int(1) ["parentNode"]=> 
string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object 
value omitted)" ["firstChild"]=> string(22) "(object value omitted)" 
["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> NULL 
["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" 
["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> 
NULL ["prefix"]=> string(0) "" ["localName"]=> string(3) "div" ["baseURI"]=> NULL 
["textContent"]=> string(24) "TEXT" }

提前致谢

【问题讨论】:

  • innerHTML 不是属性。
  • 什么是$link?发布完整代码。
  • $link 是一些html代码
  • 试试$link->textContent。也许它会起作用。
  • 由于你没有提供minimal reproducible example,也没有真正回答$link是什么类型的对象的问题,我猜你使用的是DOM,在这种情况下这个问题是重复的。如果不是这种情况,您需要edit您的问题以提供足够的信息供他人回答。

标签: php getattribute


【解决方案1】:

innerHTML 不是属性,它是一个非标准的 DOM 扩展,将元素的子节点序列化(当用作 getter 时)为 HTML 字符串。

纯粹从阅读 PHP 手册来看,相当于:

  1. 在变量中创建一个空字符串($html = "");
  2. 循环遍历childNodes
  3. 将该节点的 HTML 附加到变量 ($html .= $Node->ownerDocument->saveHTML( $Node );)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-25
    • 2017-01-30
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    • 2017-10-08
    • 2015-02-04
    • 1970-01-01
    相关资源
    最近更新 更多