pass xml to php function

pla*_*t x 2 php xml

I am thinking of passing a XML string to a function then I'll return the parent node together with its value.

Say for an example:

$xml = "<Student><Name>Jee Pee</Name><Age>16</Age></Student>";
runXmltoStr($xml);

function runXmltoStr($xml)
{
// This is where I can't figure out where to start
// In my mind, I do have this output
//
// Student
// Name: Jee Pee
// Age: 16
}
Run Code Online (Sandbox Code Playgroud)

Tim*_*per 6

You should use an XML parser, such as SimpleXML:

$xml_node = simplexml_load_string($xml);
$xml_node->Name; // Jee Pee
$xml_node->Age; // 16
Run Code Online (Sandbox Code Playgroud)