Jump to content

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


ptex

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]
Link to comment
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.
Link to comment
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.