I'm trying to echo Norwegian language if there is a xmllang="no" if not echo "noname". Like
000000000121698001,text 000000000121699001,noname
But this is only returning all productids that have a xmllang="no" and not printing productid with no xmllang="no"
XML
<catalog>
<product productid="000000000121698001">
<displayname xmllang="da">text</displayname>
<displayname xmllang="fi">text</displayname>
<displayname xmllang="no">text</displayname>
<displayname xmllang="sv">text</displayname>
</product>
<product productid="000000000121699001">
<displayname xmllang="da">test</displayname>
<displayname xmllang="x-default">test</displayname>
<displayname xmllang="sv">test</displayname>
</product>
PHP
foreach ($xml->product as $product) {
foreach ($product->displayname as $name) {
switch((string) $name['xmllang']) {
case 'no':
echo $product->attributes()->productid. ",";
if (isset($name)){
echo $name. ",", PHP_EOL;
} else {
echo 'noname ,';
}
echo "<br>\n";
}
}
}
Aucun commentaire:
Enregistrer un commentaire