How can the output of extracted data from an XML file be formatted or manipulated in PHP, as shown in the example provided?
To format or manipulate the output of extracted data from an XML file in PHP, you can use PHP's SimpleXML extension to parse the XML file and access the data. You can then loop through the XML elements, extract the desired data, and format it as needed using PHP functions.
<?php
// Load the XML file
$xml = simplexml_load_file('data.xml');
// Loop through the XML elements and extract data
foreach ($xml->children() as $child) {
// Extract and format the data as needed
$name = (string) $child->name;
$age = (int) $child->age;
// Output the formatted data
echo "Name: $name, Age: $age <br>";
}
?>