scott.stephan Posted July 28, 2009 Share Posted July 28, 2009 I currently have a little test I'm trying to run and hitting a wall. <?php $header_img_urls=array('http://ilovepr.com/media/upload/image/tile1(1).jpg','http://ilovepr.com/media/upload/image/vegg-tile.jpg','http://ilovepr.com/media/upload/image/tile2(2).jpg'); $rand_img=rand(0,count($header_img_urls)-1); $url=$header_img_urls[$rand_img]; ?> "gfgcv"; <?php echo $url; ?> <h1><img alt="" src="<?php $url; ?>" /> </h1> It echos fine, but it never outputs anythig to the "src". It comes up blank everytime. What stupid thing am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/167859-solved-using-php-to-nab-a-random-url-and-display/ Share on other sites More sharing options...
WolfRage Posted July 28, 2009 Share Posted July 28, 2009 You have to use echo in both places. Because you did not tell PHP what to do with the variable url the second time around. <h1><img alt="" src="<?php echo $url; ?>" /> </h1> Quote Link to comment https://forums.phpfreaks.com/topic/167859-solved-using-php-to-nab-a-random-url-and-display/#findComment-885319 Share on other sites More sharing options...
scott.stephan Posted July 28, 2009 Author Share Posted July 28, 2009 Ugh. Really? I can be so dumb sometimes. Thanks a bunch! Quote Link to comment https://forums.phpfreaks.com/topic/167859-solved-using-php-to-nab-a-random-url-and-display/#findComment-885326 Share on other sites More sharing options...
WolfRage Posted July 28, 2009 Share Posted July 28, 2009 No Problem. It happens. Quote Link to comment https://forums.phpfreaks.com/topic/167859-solved-using-php-to-nab-a-random-url-and-display/#findComment-885330 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.