OVH Cloud OVH Cloud

ajouter attribut

2 réponses
Avatar
frankiesayrelax
Bonjour

J'utilise pour mon site un petit script qui affiche une image différente à
chaque actualisation.

***********************
<?php
$RANDOM_IMG_FILE = "list_img.txt";
srand((double)microtime()*1000000);
if (file_exists($RANDOM_IMG_FILE)) {
$arry = file($RANDOM_IMG_FILE);
for($i = 0; $i < sizeof($arry) ; $i++) {
if (preg_match("/\w+/", $arry[$i]))
$good_arry[$j++] = chop($arry[$i]);
}
$randval = rand(0, sizeof($good_arry) -1);
$html_result = "<IMG SRC=\"$good_arry[$randval]\">";
} else {
$html_result = "Erreur, sur le fichier $RANDOM_IMG_FILE";
}
?>
************************

Dans la ligne

$html_result = "<IMG SRC=\"$good_arry[$randval]\">";

je souhaite intégrer l'attribut alt="image_hasard" pour que la page soit
valide w3.
Comment faire svp?

Merci
--
pouêt

2 réponses

Avatar
Olivier Miakinen

Dans la ligne

$html_result = "<IMG SRC="$good_arry[$randval]">";

je souhaite intégrer l'attribut alt="image_hasard" pour que la page soit
valide w3.
Comment faire svp?


Ça me semble assez simple :
$html_result = "<img src="$good_arry[$randval]"
alt="image_hasard">";

Ou plus simplement encore :
$html_result = "<img src='$good_arry[$randval]'
alt='image_hasard'>";

Avatar
frankiesayrelax
Dixit Olivier Miakinen :


Dans la ligne

$html_result = "<IMG SRC="$good_arry[$randval]">";

je souhaite intégrer l'attribut alt="image_hasard" pour que la page soit
valide w3.
Comment faire svp?


Ça me semble assez simple :
$html_result = "<img src="$good_arry[$randval]"
alt="image_hasard">";

Ou plus simplement encore :
$html_result = "<img src='$good_arry[$randval]'
alt='image_hasard'>";


Maintenant que ça marche c'est vrai que ça parraît bcp plus simple :o) Merci
beaucoup!