Jump to content

Archived

This topic is now archived and is closed to further replies.

ptex

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

Recommended Posts



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]

Share this post


Link to post
Share on other sites
Change:
[code]echo ("<img src=\"$imgpath\"alt="Welcome to"/>");[/code]
To:
[code]echo "<img src='". $imgpath. "' alt='Welcome to'/>";[/code]

Share this post


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

Share this post


Link to post
Share on other sites
you didn't put and \ in front of the " in the alt
using ' has as similar effect

Share this post


Link to post
Share on other sites
you can't use double quotes inside double quotes like this:

[code]echo "name = "blah" value="blah"";[/code]

you have to use escape characters to do that:

[code]echo "name = \"blah\" value = \"blah\"";[/code]

or else use single quotes like shown above:

[code]echo "name = 'blah' value = 'blah'";[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.