ptex Posted May 25, 2006 Share Posted May 25, 2006 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 imageecho ("<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]<?phpinclude ("randimage.php");?> [/PHP Code] Link to comment https://forums.phpfreaks.com/topic/10442-i-need-to-add-a-alt-to-a-image-but-cant/ Share on other sites More sharing options...
AndyB Posted May 25, 2006 Share Posted May 25, 2006 Change:[code]echo ("<img src=\"$imgpath\"alt="Welcome to"/>");[/code]To:[code]echo "<img src='". $imgpath. "' alt='Welcome to'/>";[/code] Link to comment https://forums.phpfreaks.com/topic/10442-i-need-to-add-a-alt-to-a-image-but-cant/#findComment-38939 Share on other sites More sharing options...
ptex Posted May 25, 2006 Author Share Posted May 25, 2006 [!--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 https://forums.phpfreaks.com/topic/10442-i-need-to-add-a-alt-to-a-image-but-cant/#findComment-38942 Share on other sites More sharing options...
kooper Posted May 25, 2006 Share Posted May 25, 2006 you didn't put and \ in front of the " in the altusing ' has as similar effect Link to comment https://forums.phpfreaks.com/topic/10442-i-need-to-add-a-alt-to-a-image-but-cant/#findComment-38954 Share on other sites More sharing options...
.josh Posted May 25, 2006 Share Posted May 25, 2006 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 https://forums.phpfreaks.com/topic/10442-i-need-to-add-a-alt-to-a-image-but-cant/#findComment-38993 Share on other sites More sharing options...
ptex Posted May 25, 2006 Author Share Posted May 25, 2006 Got it thanks Link to comment https://forums.phpfreaks.com/topic/10442-i-need-to-add-a-alt-to-a-image-but-cant/#findComment-39006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.