Hallo,
ich hab einen XML-Feed in dem der Preis und der Name des Produkts drinsteht. Die Preise sind aber nicht geordnet. Wie kann ich die ordnen?
CODE <?php
$content = "
<result>
<titel>Produkt 1</titel>
<preis>20</preis>
</result>
<result>
<titel>Produkt 2</titel>
<preis>2</preis>
</result>
<result>
<titel>Produkt 3</titel>
<preis>11</preis>
</result>";
preg_match_all("|<result>(.*)</result>|Uism",$content, $items, PREG_PATTERN_ORDER);
for ($i=0;$i<count($items[1]);$i++)
{
preg_match_all("|<titel>(.*)</titel>(.*)<preis>(.*)</preis>|Uism",$items[1][$i], $regs, PREG_PATTERN_ORDER);
$titel = $regs[1][0];
$preis = $regs[3][0];
echo "$titel - $preis Euro<br>";
}
?>
Wie mache ich das jetzt mit PHP damit ich folgendes Ergebnis hab:
Produkt 2 - 2 Euro
Produkt 3 - 11 Euro
Produkt 1 - 20 Euro
MFG
Florian
ich hab einen XML-Feed in dem der Preis und der Name des Produkts drinsteht. Die Preise sind aber nicht geordnet. Wie kann ich die ordnen?
CODE <?php
$content = "
<result>
<titel>Produkt 1</titel>
<preis>20</preis>
</result>
<result>
<titel>Produkt 2</titel>
<preis>2</preis>
</result>
<result>
<titel>Produkt 3</titel>
<preis>11</preis>
</result>";
preg_match_all("|<result>(.*)</result>|Uism",$content, $items, PREG_PATTERN_ORDER);
for ($i=0;$i<count($items[1]);$i++)
{
preg_match_all("|<titel>(.*)</titel>(.*)<preis>(.*)</preis>|Uism",$items[1][$i], $regs, PREG_PATTERN_ORDER);
$titel = $regs[1][0];
$preis = $regs[3][0];
echo "$titel - $preis Euro<br>";
}
?>
Wie mache ich das jetzt mit PHP damit ich folgendes Ergebnis hab:
Produkt 2 - 2 Euro
Produkt 3 - 11 Euro
Produkt 1 - 20 Euro
MFG
Florian