循环从XML文件获取数据

时间:2018-10-02 11:57:38

标签: php xml loops

我正在尝试在PHP中创建一个循环,以从目录中的XML文件获取信息。

<?php
$files = scandir('articles/');
foreach($files as $file) {
        $article = simplexml_load_file($file);    
        $article_name = $article->LV_ARTICLES_DESCRIPTIONANDMEASURE->LV_ARTICLES_LANG_NL;   
        $article_specification = $article->LV_ARTICLES_SPECIFICATION->LV_ARTICLES_LANG_NL;
        $article_price_incl = number_format((float)$article->LV_ARTICLES_PRICE_SHOW, 2, '.', '');
        $article_shortinfo = $article->LV_ARTICLES_SHORTMEMO->LV_ARTICLES_LANG_NL;
        $article_image = $article->LV_ARTICLES_PICTUREZOOM;
?>
            <div clas="name" style="font-size:22px; width:100%; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Naam:</li><li><?php echo $article_name;?></li></ul></div>
            <div clas="specs" style="font-size:22px; width:100%; background-color:#f7f7f7; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Specificaties:</li><li><?php echo $article_specification;?></li></ul></div>
            <div clas="name" style="font-size:22px; width:100%; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Prijs inclusief BTW:</li><li>€<?php echo $article_price_incl;?></li></ul></div>
            <div clas="specs" style="font-size:22px; width:100%; background-color:#f7f7f7; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Omschrijving:</li><li><?php echo $article_shortinfo;?></li></ul></div>
            <div style="text-align:center;"><img src="images/<?php echo $article_image; ?>"></div>
<?php
}
?>

<?xml version="1.0" encoding="UTF-8"?>
<Logivert>
  <LV_ARTICLES_DESCRIPTIONANDMEASURE>
    <LV_ARTICLES_LANG_NL><![CDATA[Recoverage Intensive Moisture Balance]]></LV_ARTICLES_LANG_NL>
  </LV_ARTICLES_DESCRIPTIONANDMEASURE>
  <LV_ARTICLES_SPECIFICATION>
    <LV_ARTICLES_LANG_NL><![CDATA[Heerlijk]]></LV_ARTICLES_LANG_NL>
  </LV_ARTICLES_SPECIFICATION>
  <LV_ARTICLES_PRICE_CURRNAME>
    <LV_ARTICLES_LANG_NL><![CDATA[&euro;]]></LV_ARTICLES_LANG_NL>
  </LV_ARTICLES_PRICE_CURRNAME>
  <LV_ARTICLES_PRICE_SHOW>39.500000</LV_ARTICLES_PRICE_SHOW>
  <LV_ARTICLES_SHORTMEMO>
    <LV_ARTICLES_LANG_NL><![CDATA[ <p><div>Deze oil free moisturizer is een heerlijke, lichte dagelijkse moisturizer, voor de vette, gevoelige en gecombineerde huid. Heeft een drievoudige werking, voedt, beschermt en vertraagt het verouderingsproces.</div>  <div><br /></div>  <div>De lichte structuur wordt snel opgenomen door de huid. Voor dagelijks gebruik. </div>  <div><br /></div>  <div>Previlient&#8482;, hyaluronzuur en power antioxidanten</div>  <div><br /></div>  <div>Alle producten binnen de nieuwe Bio Ac ve by Mineral Care RECOVERAGE&#8482;-lijn bevatten als key-ingredie&#776;nt Previlient&#8482;. Dit is een cocktail van de natuurlijke ingredienten pure Ribose en Artemia-extract. Deze combinatie stimuleert een gezonde celvernieuwing en heeft een krachtige anti-ageing effect. De toegvoegde hyaluronzuur, moisturizers en Dode Zeemineralen versterken en ondersteunen de natuurlijke vochtbalans van de huid. Een synergetische mix van de power antioxidanten Vitamine C, E en Groene Thee-extract beschermen de huid zowel van binnenuit als van buitenaf. </div>  </p>]]></LV_ARTICLES_LANG_NL>
  </LV_ARTICLES_SHORTMEMO>
  <LV_ARTICLES_LONGMEMO>
    <LV_ARTICLES_LANG_NL><![CDATA[]]></LV_ARTICLES_LANG_NL>
  </LV_ARTICLES_LONGMEMO>
  <LV_ARTICLES_PICTUREZOOM>zoom/m_692.jpg</LV_ARTICLES_PICTUREZOOM>
</logivert>

当我运行页面时,它仍然是空白的。如果我回显$file变量,则输出为:...article_1.xmlarticle_2.xmlarticle_3.xml etc.

我该怎么办?循环出了什么问题?

0 个答案:

没有答案