Pop\Dom\Dom::render PHP Method

render() public method

Method to render the document and its child elements.
public render ( boolean $ret = false ) : mixed
$ret boolean
return mixed
    public function render($ret = false)
    {
        $this->output = null;
        if (null !== $this->doctype) {
            $this->output .= str_replace('[{charset}]', $this->charset, Dom::$doctypes[$this->doctype]);
        }
        foreach ($this->childNodes as $child) {
            $this->output .= $child->render(true, 0, $this->indent);
        }
        // If the return flag is passed, return output.
        if ($ret) {
            return $this->output;
            // Else, print output.
        } else {
            if (null !== $this->doctype) {
                if (!headers_sent()) {
                    header("HTTP/1.1 200 OK");
                    header("Content-type: " . $this->contentType);
                }
            }
            echo $this->output;
        }
    }

Usage Example

Example #1
0
 public function testRender()
 {
     $d = new Dom(Dom::XHTML11, 'utf-8', new Child('p', 'This is another paragraph'));
     $d->addChild(new Child('p', 'This is a paragraph'));
     $code = $d->render(true);
     ob_start();
     $d->render();
     $output = ob_get_clean();
     $this->assertContains('<p>', $code);
     $this->assertContains('<p>', $output);
 }
All Usage Examples Of Pop\Dom\Dom::render