Assume that the xml file is named class.xml and has the following content:
<?xml version=”1.0″ encoding=”utf-8″?>
<class>
<student>
<id>3</id>
<name>Zhang San</name>
</student>
<student>
<id>5</id>
<name>李思</name>
</student>
</class>
1. Load the xml file and generate a simpleXml object
// Assume that the xml file is in the current path
$xml = simplexml_load_file('class.xml');
2. Find the element layer by layer according to the name of the element. And get the element content
// Assume that what you get is the content of the first name in the sub-element of the second student, that is, output Li Si. Note that the index of elements starts from 0
echo $xml->student[1]->name[0];