SimpleXML asXML Not Working As Expected

Help file says:

SimpleXMLElement::asXML — Return a well-formed XML string based on SimpleXML element

However, the following:

$url = "https://gunretort.xyz/api.php?action=query&list=search&srsearch=NewTag&srwhat=text&srnamespace=0|3000&format=xml";
$xml = simplexml_load_file($url);
echo $xml->asXML;

returns nothing. Why?

thx

When you say returns “Hello WorldBugs!” are you sure you don’t mean displays?

In other words, when you look at view-source, there are no XML elements being output.

Try this

$string = "<element><child>Hello World</child><bug>Bugs!</bug></element>";
$xml = new SimpleXMLElement($string);
//echo $xml->asXML();
$test_output = $xml->asXML();
print_r($test_output);

Because asXML is a method, not a property.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.