PHP __construct() function
Definition and Usage
__construct() function creates a new SimpleXMLElement object.
If successful, the function returns an object. If failed, it returns false.
Syntax
__construct(data,options,is_url,ns,is_prefix)
Parameter | Description |
---|---|
data | Required. A well-formed XML string or the path or URL to an XML document. |
options | Optional. Specifies additional Libxml parameters. |
is_url | Optional. Specifies whether the data parameter is a URL. Default is false. |
ns | Optional. |
is_prefix | Optional. |
Return value
Returns a SimpleXMLElement object representing the data.
Example
<?php $xmlstring = <<<XML <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note> XML; $xml = new SimpleXMLElement($xmlstring); echo $xml->body[0]; ?>
Output similar to:
Don't forget the meeting!