Note that there are some explanatory texts on larger screens.

plurals
  1. POHtml/Markup format using Picasa PHP FOREACH
    text
    copied!<p>Hi guys im trying to format an html output based on <a href="https://github.com/benrhughes/PicasaAlbums/blob/master/albums.php" rel="nofollow">this picasa script</a> using foreach, this way:</p> <pre><code>&lt;? foreach($albums as $photo) {?&gt; &lt;span&gt;&lt;img src="&lt;? echo $photo[1]; ?&gt;" border=0&gt;&lt;/a&gt;&lt;p&gt;&lt;?=$photo[0]; ?&gt;&lt;/p&gt;&lt;/span&gt; &lt;? } ?&gt; </code></pre> <p>The output is:</p> <pre><code>&lt;span&gt;&lt;img src="foto1.jpg" border=0&gt;&lt;/a&gt;&lt;p&gt;This is pict 1 Album 1&lt;/p&gt;&lt;/span&gt; &lt;span&gt;&lt;img src="foto2.jpg" border=0&gt;&lt;/a&gt;&lt;p&gt;This is pict 2 Album 1&lt;/p&gt;&lt;/span&gt; &lt;span&gt;&lt;img src="foto3.jpg" border=0&gt;&lt;/a&gt;&lt;p&gt;This is pict 3 Album 1&lt;/p&gt;&lt;/span&gt; &lt;span&gt;&lt;img src="foto4.jpg" border=0&gt;&lt;/a&gt;&lt;p&gt;This is pict 4 Album 2&lt;/p&gt;&lt;/span&gt; </code></pre> <p>But i need this:</p> <pre><code>&lt;div&gt; &lt;h1&gt;Album 1&lt;/h1&gt; &lt;span&gt;&lt;img src="foto1.jpg" border=0&gt;&lt;/a&gt;&lt;p&gt;This is pict 1 Album 1&lt;/p&gt;&lt;/span&gt; &lt;span&gt;&lt;img src="foto2.jpg" border=0&gt;&lt;/a&gt;&lt;p&gt;This is pict 2 Album 1&lt;/p&gt;&lt;/span&gt; &lt;span&gt;&lt;img src="foto3.jpg" border=0&gt;&lt;/a&gt;&lt;p&gt;This is pict 3 Album 1&lt;/p&gt;&lt;/span&gt; &lt;/div&gt; &lt;div&gt; &lt;h1&gt;Album 2&lt;/h1&gt; &lt;span&gt;&lt;img src="foto4.jpg" border=0&gt;&lt;/a&gt;&lt;p&gt;This is pict 4 Album 2&lt;/p&gt;&lt;/span&gt; &lt;/div&gt; </code></pre> <p>The idea is bring all the album in my picasa account with their pictures inside, example:</p> <pre><code>album 1 has: foto1.jpg foto2.jpg foto3.jpg album 2 has: foto4.jpg </code></pre> <p>So on ... That's it i hope someone could help me and understand better my really bad english :)</p> <p>FULL SOURCE:</p> <pre><code>&lt;?php $userid = "cramosb"; // Your Google user name $target = "PicasaBox.php/?album="; //URL to pass the name of the album to for the links $imgmax = "512"; /*------------------------------------------------------------------------------ | USER CONFIGURATION END ------------------------------------------------------------------------------*/ // *** Only modify past this point if you know what you're doing *** $insideentry = false; $tag = ""; $title = ""; $url = ""; // function to parse the start of an XML element function startElement($parser, $name, $attrs) { global $insideentry, $tag, $title, $url; if ($insideentry) { $tag = $name; if ($name == "MEDIA:CONTENT"){ $url = $attrs["URL"]; } } elseif ($name == "ENTRY") { $insideentry = true; } } // function to parse the end of an XML element function endElement($parser, $name) { global $insideentry, $tag, $title, $url, $albums; if ($name == "ENTRY") { $albums[] = array($title, $url); //echo $title . ' ' . $url; $title = ""; $url = ""; $insideentry = false; } } // function to parse the contents of an XML element function characterData($parser, $data) { global $insideentry, $tag, $title, $url; if ($insideentry) { if ($tag == "TITLE") { $title .= $data; } } } // Lets get started... // Create an XML parser, using the functions above $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); // The URL of the album feed I CHANGE THIS: $feed = "http://picasaweb.google.com/data/feed/api/user/" . $userid . "?kind=album"; TO: $feed = "http://picasaweb.google.com/data/feed/api/user/" . $userid . "?kind=photo"; // Open the feed $fp = fopen($feed,"r") or die("Error reading RSS data."); // Parse the feed while ($data = fread($fp, 4096)) xml_parse($xml_parser, $data, feof($fp)) or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); // Close the feed fclose($fp); xml_parser_free($xml_parser); foreach($albums as $album) { $htmlout .= '&lt;span&gt;&lt;a href="'. $target . $album[0] . '"&gt;&lt;img src="' . $album[1] . '" border=0&gt;&lt;/a&gt;&lt;p&gt;' . $album[0] . '&lt;/p&gt;&lt;/span&gt;'; } print $htmlout; exit; ?&gt; </code></pre>
 

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