PHP随机数组与文本,图像和图像Alt属性


PHP Random Array with Text, Image and Image Alt attribute

我刚刚制作了一个从这段代码中提取信息的随机数组。它确实可以工作,但我试图在图像中添加alt属性以便于使用屏幕阅读器等的人更容易访问。

<?php 
  $funfacts[0]['image']="img/fun-fact-white-potato.jpg"; 
  $funfacts[0]['paragraph']="White potatoes were first cultivated by local Indians in the Andes Mountains of South America.";
  $funfacts[0]['alt']="White Potato";
  $funfacts[1]['image']="img/fun-fact-strawberries.jpg"; 
  $funfacts[1]['paragraph']="Strawberries are not really a fruit or a berry but the enlarged receptacle of the flower. ";
  $funfacts[1]['alt']="A pair of Strawberries";
  $funfacts[2]['image']="img/fun-fact-oranges.jpg"; 
  $funfacts[2]['paragraph']="British sailors used to be called &ldquo;Limeys&rdquo; because they ate citrus to prevent scurvy on long sea voyages.";
  $funfacts[2]['alt']="A cut-up Orange"; 
  $funfacts[3]['image']="img/fun-fact-carrots.jpg"; 
  $funfacts[3]['paragraph']="The original carrots used to be purple. Farmers in Holland started planting orange carrots in the sixteenth century."; 
  $funfacts[3]['alt']="A pile of carrots";
  $id_funfacts = array_rand($funfacts); 
  echo  "<img src='".$funfacts[$id_funfacts]['image']. "' alt='".$funfacts[$id_funfacts]['alt'] "' >"; 
  echo  "<p>".$funfacts[$id_funfacts]['paragraph']. "</p>"; 
?>

它告诉我包含

的行
echo  "<img src='".$funfacts[$id_funfacts]['image']. "' alt='".$funfacts[$id_funfacts]['alt'] "' >"; 

是罪魁祸首,但我不确定它有什么问题。如果我不能解决这个问题,你可以看出我不是一个真正的PHP专家。

我期待你的回信。

詹姆斯

我基本上发现我在这行代码后面漏了一个句号。

echo  "<img src='".$funfacts[$id_funfacts]['image']. "' alt='".$funfacts[$id_funfacts]['alt'] "' >";

正确的代码是:

echo  "<img src='".$funfacts[$id_funfacts]['image']. "' alt='".$funfacts[$id_funfacts]['alt']. "' >";
如果我错过了这样简单的事情,那么是时候睡觉了!!