Note that there are some explanatory texts on larger screens.

plurals
  1. POEcho each image in an array
    primarykey
    data
    text
    <p>im using the Wikipedia API to get images and a description for my site, and I need your help with the images. Currently I'm using this:</p> <pre><code>$wurl = "http://en.wikipedia.org/w/api.php?action=query&amp;prop=extracts|info|images&amp;titles=".$wsearch."&amp;format=json&amp;explaintext&amp;redirects&amp;inprop=url&amp;indexpageids&amp;exintro"; $wjson = file_get_contents($wurl); $wdata = json_decode($wjson); $wpageid = $wdata-&gt;query-&gt;pageids['0']; if ($wpageid == -1) { } else { echo" &lt;div id='images'&gt; &amp;nbsp;&amp;nbsp;&lt;p style='padding-bottom:8px;border-bottom: 6px solid #333;width:100%;'&gt;Images for &lt;b&gt;$search&lt;/b&gt;:&lt;/br&gt;&lt;/p&gt; &lt;div class='resultbox random-color-".rand(1,3)."'&gt; "; foreach($wdata-&gt;query-&gt;pages-&gt;$wpageid-&gt;images as $iimages) { $ititle = $iimages-&gt;title; $iname = $ititle; $ifilename = str_replace(" ", "_",$iname); $idigest = md5($ifilename); $ifolder = $idigest[0] . '/' . $idigest[0] . $idigest[1] . '/' . urlencode($iname); $iurl = 'http://upload.wikimedia.org/wikipedia/commons/' . $ifolder; echo" &lt;img style='height:100px;' src='$irurl'&gt; "; } echo" &lt;/div&gt; &lt;/div&gt; "; } </code></pre> <p>To echo each individual image from the url:</p> <ul> <li><a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=extracts|info|images&amp;titles=google&amp;format=json&amp;explaintext&amp;redirects&amp;inprop=url&amp;indexpageids&amp;exintro" rel="nofollow">http://en.wikipedia.org/w/api.php?action=query&amp;prop=extracts|info|images&amp;titles=google&amp;format=json&amp;explaintext&amp;redirects&amp;inprop=url&amp;indexpageids&amp;exintro</a></li> </ul> <p>However, I can't get anything back, or at least nothing is displaying on my page. I'm very new to JSON, so can someone explain to me what I'm doing wrong? I hope you can tell me and future viewers to do it, because its really annoying... lol, anyway thanks in advance.</p> <p>EDIT:</p> <pre><code>&lt;div class="resultbox random-color-3"&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 4="" 4a="" commons-logo.svg'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" f="" fe="" crystal_clear_app_browser.png'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" e="" e5="" eric_schmidt_at_the_37th_g8_summit_in_deauville_037.jpg'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" b="" b6="" factory_1b.svg'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" a="" a4="" flag_of_the_united_states.svg'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 2="" 20="" google-logo.svg'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" b="" b7="" google1998.png'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 6="" 69="" google_appliance.jpg'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 5="" 54="" google_mountain_view_campus_dinosaur_skeleton_%27stan%27.jpg'=""/&gt; &lt;img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 8="" 8c="" google_mountain_view_campus_garden.jpg'=""/&gt; &lt;/div&gt; </code></pre> <p>it seems to be removing all the /'s and not replacing the spaces with underscores... any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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