简体   繁体   English

PHP Simple HTML Dom:前置

[英]PHP Simple HTML Dom: Prepend

I would like to get this code: 我想获得以下代码:

<div class="class1">Any Text<div>Or any other Content</div></div>

to this: 对此:

<div class="class1 another_class"><div class="extra"></div>Any Text<div>Or any other Content</div></div>

with the PHP Simple HTML Dom Parser PHP Simple HTML Dom解析器

This is my first part: 这是我的第一部分:

foreach($html->find(".class1") as $element) {
    $element->class="class1 another_class";
}

But how can I add the "extra"-div? 但是,如何添加“额外” -div?

($e->innertext)Read or write the inner HTML text of element. ($ e-> innertext)读取或写入元素的内部HTML文本。 may be this gonna work.. :) 也许这会工作.. :)

foreach($html->find("div.class1") as $element) {
    $element->innertext = '<div class="extra"></div>' . $element->innertext;
    $element->class = "class1 another_class";
}

The correct syntax is this; 正确的语法是这样;

$ret = $html->find('div.foo');
//OR
$ret = $html->find('div[class=foo]');

source: http://simplehtmldom.sourceforge.net/manual.htm 来源: http//simplehtmldom.sourceforge.net/manual.htm
How to find HTML elements? 如何找到HTML元素? section, tab Advanced 部分,高级标签

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

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