3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.2.1 - 5.6.28, 7.0.0 - 7.1.0
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 hhvm-3.12.0
Warning: No such file or directory in /in/cF4kv on line 5 Notice: Cannot access property on non-object in /in/cF4kv on line 10 Warning: Invalid argument supplied for foreach() in /in/cF4kv on line 78
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.1.0 - 5.2.0
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.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.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