Advertisement
thebys

random thumb obrazek ze staticky stranky

Apr 5th, 2015
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Protože lenost je taky cesta.
  4.  * User: Thebys
  5.  * Date: 6. 4. 2015
  6.  * Time: 1:50
  7.  * vezme to statickou stránku galerie, vytáhne to všechny obrázky jejichž cesta obsahuje thumb a náhodný to zobrazí s odkazem do galerie...
  8.  * */
  9.  
  10. $dom = new DOMDocument;
  11. $galerie = file_get_contents("obsah/fotogalerie.php");
  12. $galerie = mb_convert_encoding($galerie, 'HTML-ENTITIES', "UTF-8");
  13. $dom->loadHTML($galerie);
  14. $images = $dom->getElementsByTagName('img');
  15. $thumbs = array();
  16. $i = 0;
  17. foreach ($images as $image) {
  18.     if (strpos($image->getAttribute("src"), "thumbs") !== FALSE) {
  19.         $thumbs[$i] = $image->getAttribute("src");
  20.         $i++;
  21.     } else {
  22.         continue;
  23.     }
  24. }
  25. $thumbURL = $thumbs[rand(0, (count($thumbs) - 1))];
  26. echo "<span class=\"boxh\">Náhodný obrázek z galerie</span>";
  27. echo "<div class=\"nahodnyObrazek\">";
  28. echo "<a href=\"index.php?s=obsah/fotogalerie\"><img src=\"$thumbURL\"></a>";
  29. echo "</div>";
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement