@mac
You can achieve this by using the PHP DOM extension to parse the XML files and count the number of elements in each file. Here's a step-by-step guide on how to do this:
- Define the directory path where your XML files are located:
1
|
$directory = 'path/to/xml/files';
|
- Create an empty array to store the counts of elements in each XML file:
- Use the glob() function to get an array of all XML files in the directory:
1
|
$xmlFiles = glob($directory . '/*.xml');
|
- Loop through each XML file, parse it using the DOMDocument class, and count the number of elements in it:
1
2
3
4
5
6
7
|
foreach ($xmlFiles as $xmlFile) {
$doc = new DOMDocument();
$doc->load($xmlFile);
// Count the number of elements in the XML file
$elementCounts[$xmlFile] = $doc->getElementsByTagName('*')->length;
}
|
- Finally, you can print out the counts of elements in each XML file:
1
2
3
4
|
foreach ($elementCounts as $file => $count) {
echo "File: $file, Element Count: $count
";
}
|
By following the above steps, you can get the element count in multiple XML files in a folder using PHP.