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] Quote 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] Quote 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. Quote 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 Quote 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] Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.