That should get you started:
<?php
require_once(__DIR__ . '/simplesamlphp/_include.php');
$xmldata = trim($_POST['xml_metadata']);
if (!empty($xmldata)) {
$xmlUtils = new \SimpleSAML\Utils\XML();
$xmlUtils->checkSAMLMessage($xmldata, 'saml-meta');
$entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsString($xmldata);
// get all metadata for the entities
foreach ($entities as &$entity) {
$entity = [
'saml20-idp-remote' => $entity->getMetadata20IdP(),
];
}
// transpose from $entities[entityid][type] to $output[type][entityid]
$arrayUtils = new \SimpleSAML\Utils\Arrays();
$output = $arrayUtils->transpose($entities);
if(isset($output['saml20-idp-remote']) && count($output['saml20-idp-remote']) === 1){
$finalOutput = '';
foreach($output['saml20-idp-remote'] as $oneMetadata){
// If there is entityDescriptor then uset it
if(isset($oneMetadata['entityDescriptor'])){
unset($oneMetadata['entityDescriptor']);
}
// If there is "expire" in the metadata remove it as we can forget to remove it and it can expire in the future causing issues
if(isset($oneMetadata['expire'])){
unset($oneMetadata['expire']);
}
$finalOutput = $oneMetadata;
}
print_r($finalOutput);