0

I'm trying to create a loop in PHP to get information from the XML files in a directory.

<?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>

When I run the page it is still blank. If I echo the $file variable the output is: ...article_1.xmlarticle_2.xmlarticle_3.xml etc.

What can I do? What's wrong with the loop?

Bryan
  • 1
  • 3
  • Try to echo $article_image – E3Im Oct 02 '18 at 12:00
  • We'll be able to help you a lot more easily if we can see a sample of the XML – iainn Oct 02 '18 at 12:03
  • fyi: `clas` should be `class`. "_When I run the page it is still blank._" So not even "Naam:", "Specificaties:" show up? – brombeer Oct 02 '18 at 12:04
  • echo $article and see what happens, also check if echoing $article->LV_ARTICLES_DESCRIPTIONANDMEASURE is returning something, then check if $article->LV_ARTICLES_DESCRIPTIONANDMEASURE->LV_ARTICLES_LANG_NL is returning something. debug step for step. – NickGames Oct 02 '18 at 12:12
  • I tried but, the output is empty. – Bryan Oct 02 '18 at 12:19
  • 2
    A blank page usually means a PHP error; see [advice here on how to display errors or find your error logs](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851). – IMSoP Oct 02 '18 at 12:20
  • 1
    XML tags are case-sensitive - your opening `Logivert` tag doesn't match the closing `logivert`. – iainn Oct 02 '18 at 12:27
  • I'm marking this as a duplicate of the reference question; there may be various bugs in this code, but if you go through your error logs you may be able to fix some of them yourself. If you are left with some errors that you don't understand, or still can't get the code to work, please ask a new question containing a clear question and a [mcve]. – IMSoP Oct 02 '18 at 12:30

0 Answers0