jo: Alt-Tag zu Zufallsbild

Beitrag lesen

» <?php

srand();
/* Erzeugt eine Zufallszahl von 1 - n */
$zufall = rand(1, 16);
/* Zusammensetzen des Bildpfades */
$bild = "images/bild" . $zufall . ".jpg";
echo "<img src="" . $bild . "">";
?>

  
<?  
//hier deine namen angeben  
$altNames=array("altName1","altName2","altName3","altName4","altName5","altName6","altName7","altName8","altName9","altName10","altName11","altName12","altName13","altName14","altName15","altName16");  
  
//die letzte zeile ersetzten  
echo "<img src=\"" . $bild . "\" alt=\"$altNames[$zufall ]\">";  
  
  
//lern PHP :-) es lohnt sich  
?>