Jump to content


Photo

I need to add a "alt" to a image but can't?


  • Please log in to reply
5 replies to this topic

#1 ptex

ptex
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 May 2006 - 03:28 PM



Why won't this work?

[PHP Code]
<?php
// Generate random number from 1-10
$imgnum = rand(1, 10);
// Set image path and file name with generated number
$imgpath = "images/TopBanner" . $imgnum . ".jpg";
// Display image
echo ("<img src=\"$imgpath\"alt="Welcome to"/>");
?>
[/PHP Code]

I can't validate my page because the banner image has no alt and no closing tag but I get a error when I try the above. Here is my include file.

[PHP Code]
<?php
include ("randimage.php");
?>
[/PHP Code]

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 25 May 2006 - 03:34 PM

Change:
echo ("<img src=\"$imgpath\"alt="Welcome to"/>");
To:
echo "<img src='". $imgpath. "' alt='Welcome to'/>";

Legend has it that reading the manual never killed anyone.
My site

#3 ptex

ptex
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 May 2006 - 03:45 PM

[!--quoteo(post=377051:date=May 25 2006, 11:34 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 25 2006, 11:34 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Change:
echo ("<img src=\"$imgpath\"alt="Welcome to"/>");
To:
echo "<img src='". $imgpath. "' alt='Welcome to'/>";
[/quote]
Thanks it worked but why? If you don't mind or point me to a page in the Manual.

#4 kooper

kooper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 May 2006 - 04:47 PM

you didn't put and \ in front of the " in the alt
using ' has as similar effect
if ($2b || !$2b)
{
echo "that is the question";
}

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 May 2006 - 07:11 PM

you can't use double quotes inside double quotes like this:

echo "name = "blah" value="blah"";

you have to use escape characters to do that:

echo "name = \"blah\" value = \"blah\"";

or else use single quotes like shown above:

echo "name = 'blah' value = 'blah'";


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 ptex

ptex
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 May 2006 - 08:44 PM

Got it thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users