I have several functions in the class that return saveHTML (). After I repeat several functions in the saveHTML () class, it repeats some of the HTML. At first I solved this by running saveHTML ($ node), but now it does not seem to be an option.
I did not know that saveHTML ($ domnode) was only available in PHP 5.3.6, and I did not control the server on which I uploaded the files, so now I have to make it compatible with PHP 5.2.
For simplicity, and just to show my problem, it looks something like this:
<?php class HTML { private $dom; function __construct($dom) { $this->dom = $dom; } public function create_paragraph() { $p = $this->dom->createElement('p','Text 1.'); $this->dom->appendChild($p); return $this->dom->saveHTML(); } public function create_paragraph2() { $p = $this->dom->createElement('p','Text 2.'); $this->dom->appendChild($p); return $this->dom->saveHTML(); } } $dom = new DOMDocument; $html = new HTML($dom); ?> <html> <body> <?php echo $html->create_paragraph(); echo $html->create_paragraph2(); ?> </body> </html>
Outputs:
<html> <body> <p>Text 1.</p> <p>Text 1.</p><p>Text 2.</p> </body>
I have an idea why this happens, but I have no idea how not to repeat it without saveHTML ($ domnode). How can I make it work with PHP 5.2?
Here is an example of what I want to do:
http://codepad.viper-7.com/o61DdJ
Tek
source share