Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<SimpleXMLElement::saveXMLSimpleXMLElement::valid>
^SimpleXMLElementLast updated: Mon, 26 Oct 2026

SimpleXMLElement::__toString

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

SimpleXMLElement::__toString — Returns the string content

Description

public function SimpleXMLElement::__toString(): string

Returns text content that is directly in this element. Does not return text content that is inside this element's children.

Parameters

This function has no parameters.

Return Values

Returns the string content on success or an empty string on failure.

Examples

Example #1 Get string content

<?php
$xml = new SimpleXMLElement('<a>1 <b>2 </b>3</a>');
echo $xml;
?>

The above example will output:

1 3

See Also


<SimpleXMLElement::saveXMLSimpleXMLElement::valid>
^SimpleXMLElementLast updated: Mon, 26 Oct 2026