PHP __toString() Function

❮ PHP SimpleXML Reference

Example

Return the string content of the <note> element:

<?php
$xml = new SimpleXMLElement("<note>Hello <to>Tove</to><from>Jani</from>World!</note>");
echo $xml;
?>
Run Example »

Definition and Usage

The __toString() function returns the string content of an element.

This function returns the string content that is directly in the element - not the string content that is inside this element's children!


Syntax

SimpleXMLElement::__toString()

Technical Details

Return Value: The string content on success. An empty string on failure
PHP Version: 5.3+

❮ PHP SimpleXML Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.