Note that there are some explanatory texts on larger screens.

plurals
  1. POXML Loop Statement in PHP
    text
    copied!<p>Hey, i have an simpleXMLElement document that features an array of data to do with an artist's albums. </p> <p>Below is an extract of that XML</p> <pre><code> [2] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [num] =&gt; 3 [type] =&gt; artist ) [title] =&gt; DJ Tiësto [uri] =&gt; http://www.discogs.com/artist/DJ+Ti%C3%ABsto [summary] =&gt; DJ Tiësto Tijs Michiel Verwest Dutch trance DJ &amp; producer. </code></pre> <p>In this XML document there are multiple different types of information from artist info to titles of albums. I want to extract certain parts of this data and echo them out. For instance i want to extract the summary's of the array entries that have the [type] defined to artist. I'm guessing i would use a foreach loop that went through all the entries and checked if this was true? Is this the right way to go about it.</p> <p>I apologise for my confusing explanation</p> <p>---- EDIT ----</p> <p>Heres the PHP code that grabs the data - </p> <pre><code>&lt;?php $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://www.discogs.com/search?type=all&amp;" . "q=DJ+Tiësto&amp;" . "f=xml&amp;" . "api_key=&lt;key&gt;"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_ENCODING, "gzip"); $result = curl_exec($curl); curl_close($curl); $xmlmusic = new SimpleXMLElement($result,NULL,true); foreach ($xmlmusic as $xm) { $attrs = $xm-&gt;attributes(); if($attrs["type"] == "title") echo $xm-&gt;summary."\n"; } </code></pre> <p>?></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload