Reputation: 1137
I use simple_html_dom.php
I want to remove the first child of a element :
The HTML :
<div id="result">
<a class="result_type1" href="#">The title</a>
<span class="item">item</span>
<span class="more">more</span>
<span class="description">description</span>
</div>
The PHP test 1 :
foreach($html2->find("div[id=result]") as $element)
{
$element->children(0)->outertext=$element->children(1)->outertext;
$element->children(1)->outertext=$element->children(2)->outertext;
$element->children(2)->outertext=$element->children(3)->outertext;
$element->children(3)->outertext="";
echo $element->children(0)->plaintext;
}
Result (not good) :
The title
PHP test 2
foreach($html2->find("div[id=result]") as $element)
{
$element->children(0)->outertext=$element->children(1)->outertext;
$element->children(1)->outertext=$element->children(2)->outertext;
$element->children(2)->outertext=$element->children(3)->outertext;
$element->children(3)->outertext="";
echo $element->children(0)->outertext;
}
Result (good):
<span class="item">item</span>
And I don't get the same item. With plaintext, I get the element that should be removed
Upvotes: 1
Views: 171
Reputation: 1137
It appears that these three properties (outertext, innertext and plaintext) are separated when the information is processed, as stored in a multidimensional array:
If you make a change to an element with "outerText", the other two properties do not change:
element1 plaintext: "text 1",
outerText: "<span> text 2 </ span>",
InnerText: "text 1"
Same if you make a change with "plaintext".
element1 plaintext: "text 2"
outerText: "<div> text 1 </ div>",
InnerText: "text 1" .
Only the "InnerText" property affects the other two properties ...
element1 plaintext: "text 2"
outerText: "<div> text 2 </ div>",
InnerText: "text 2"
by against if you change an element with "href" it will affect "outertext" value.
element1 href : "link2",
outerText: "<a href="link2"> </a>",
Inversly change with "outerText" not influence "href".
element1 href : "link1",
outerText: "<a href="link2"> </a>",
Upvotes: 1