3v4l.org

run code in 300+ PHP versions simultaneously
<?php // ---------------------- get article info ---------------------- $articles = simplexml_load_file('xml/shoparticles.xml'); // <-- loads local article database //////(1)fetch multpiple article ids: $ids = array('article1' , 'article2', 'article3'); { $output = '<div class="product">'; foreach ($articles->article as $article) { //////(2)fetch multiple article ids: if (in_array($article['id'], $ids)) { // fetch single article id: if ($article['id'] == 'article1') { **execute code** if ($article['id'] == '10012037') { // get the productType resource $productType = simplexml_load_file($article->product->productType->attributes('xlink', true)); $output .= '<li class="clearfix" id="article_'.$article['id'].'"> <form method="post">'; $output .= '<img src="' . (string)$article->resources->resource->attributes('xlink', true) . ',width=560,height=560" alt="' . $article->name . '" class="preview" />'; // add a select with available sizes $output .= '<select id="size-select" name="size">'; foreach($productType->sizes->size as $val) { $output .= '<option value="'.$val['id'].'">'.$val->name.'</option>'; } $output .= '</select>'; // add a list with available colors $output .= '<ul class="colors" name="color">'; $freecolor = $article->product->restrictions->freeColorSelection; $colorid = $article->product->appearance['id']; foreach ($productType->appearances->appearance as $appearance) { //single color articles if ($appearance['id'] == intval($colorid) && $freecolor == "false") { $output .= '<li value="'.$appearance['id'].'">' . '<a href="javascript:void(0)" target="" title="'. $appearance->name .'">' . '<img src="'. $appearance->resources->resource->attributes('xlink', true) .'" alt="'. $appearance->name .'" name="'. $appearance->name .'" /> </a> </li>'; break; } //multi color articles if ($freecolor == "true") { $output .= '<li value="'.$appearance['id'].'">' . '<a href="javascript:void(0)" target="" title="'. $appearance->name .'">' . '<img src="'. $appearance->resources->resource->attributes('xlink', true) .'" alt="'. $appearance->name .'" name="'. $appearance->name .'" /> </a> </li> '; } } $output .= '</ul>'; //quantity $output .= 'quantity: <input type="text" value="1" maxlenght="2" id="quantity" size="1" name="quantity"> <br /><br />'; //show price $output .= 'price: <b>$'. $article->price->vatExcluded .'</b>'; //------hidden inputs for basket creation--------- //appearance/color $output .= '<input type="hidden" ' . 'value="'. $article->product->appearance['id'] .'" id="appearance_'.$article['id'].'" name="appearance" />'; //article id $output .= '<input type="hidden" value="'. $article['id'] .'" id="article_'.$article['id'].'" name="article" />'; //submits all info to basket $output .= '<input type="submit" name="submit" value="Add to basket" style="float:right" /></form></li>'; } //if $article } //for each $article $output .= '</div>'; ?>
Output for 8.3.0 - 8.3.6
Warning: simplexml_load_file(): I/O warning : failed to load external entity "xml/shoparticles.xml" in /in/cF4kv on line 5 Warning: Attempt to read property "article" on false in /in/cF4kv on line 10 Warning: foreach() argument must be of type array|object, null given in /in/cF4kv on line 10
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: simplexml_load_file(): I/O warning : failed to load external entity "xml/shoparticles.xml" in /in/cF4kv on line 5 Warning: Attempt to read property "article" on bool in /in/cF4kv on line 10 Warning: foreach() argument must be of type array|object, null given in /in/cF4kv on line 10
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Warning: simplexml_load_file(): I/O warning : failed to load external entity "xml/shoparticles.xml" in /in/cF4kv on line 5 Notice: Trying to get property 'article' of non-object in /in/cF4kv on line 10 Warning: Invalid argument supplied for foreach() in /in/cF4kv on line 10
Output for 5.1.0 - 5.1.6, 5.2.0, 7.3.32 - 7.3.33, 7.4.26
Warning: simplexml_load_file(): I/O warning : failed to load external entity "xml/shoparticles.xml" in /in/cF4kv on line 5 Warning: Invalid argument supplied for foreach() in /in/cF4kv on line 10
Output for 5.2.1 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33
Warning: simplexml_load_file(): I/O warning : failed to load external entity "xml/shoparticles.xml" in /in/cF4kv on line 5 Notice: Trying to get property of non-object in /in/cF4kv on line 10 Warning: Invalid argument supplied for foreach() in /in/cF4kv on line 10
Output for 5.0.0 - 5.0.5
Warning: I/O warning : failed to load external entity "xml/shoparticles.xml" in /in/cF4kv on line 5 Warning: Invalid argument supplied for foreach() in /in/cF4kv on line 10
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: simplexml_load_file() in /in/cF4kv on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: simplexml_load_file() in /in/cF4kv on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: simplexml_load_file() in /in/cF4kv on line 5

preferences:
249.14 ms | 401 KiB | 343 Q