rp2006 Posted January 25, 2007 Share Posted January 25, 2007 Hey,I am setting up an Ad Rotator, i.e. randomally selecting ads to display. I have the code working execpt for displaying the advert code. I can do echo("advert1"); but how do i place the HTML code into the if bit. I always get an error when doing it.Cheers Quote Link to comment https://forums.phpfreaks.com/topic/35704-solved-html-in-php-if-statement/ Share on other sites More sharing options...
wildteen88 Posted January 25, 2007 Share Posted January 25, 2007 Wrap the html in single quotes:[code=php:0]echo '<img src="http://www.mysite.com/path/to/ad/image">';[/code]Note if you do this:[code=php:0]echo "<img src="http://www.mysite.com/path/to/ad/image">";[/code]You will have to escape the double quotes in the string too. So it will be like this:[code=php:0]echo "<img src=\"http://www.mysite.com/path/to/ad/image\">";[/code]If you dont you will get errors. As PHP will think you are ending the print/echo statement and then throw's an unexpecting string in blah bla blah. Quote Link to comment https://forums.phpfreaks.com/topic/35704-solved-html-in-php-if-statement/#findComment-169218 Share on other sites More sharing options...
rp2006 Posted January 25, 2007 Author Share Posted January 25, 2007 How would i do it with this code then ??? :-\[CODE]<!-- Begin: AdBrite --><br /><div align="center"><script type="text/javascript"> var AdBrite_Title_Color = '000000'; var AdBrite_Text_Color = '000000'; var AdBrite_Background_Color = 'FFFFFF'; var AdBrite_Border_Color = 'FFFFFF';</script><span style="white-space:nowrap;"><script src="http://ads.adbrite.com/mb/text_group.php?sid=197042&zs=3436385f3630" type="text/javascript"></script><!----><br /></span><!-- End: AdBrite -->[/CODE]Thanks Alot :) Quote Link to comment https://forums.phpfreaks.com/topic/35704-solved-html-in-php-if-statement/#findComment-169296 Share on other sites More sharing options...
wildteen88 Posted January 25, 2007 Share Posted January 25, 2007 Best of using herdoc syntax:[code=php:0]echo <<<HTMLBLOCK<!-- Begin: AdBrite --><br /><div align="center"><script type="text/javascript"> var AdBrite_Title_Color = '000000'; var AdBrite_Text_Color = '000000'; var AdBrite_Background_Color = 'FFFFFF'; var AdBrite_Border_Color = 'FFFFFF';</script><span style="white-space:nowrap;"><script src="http://ads.adbrite.com/mb/text_group.php?sid=197042&zs=3436385f3630" type="text/javascript"></script><!----><br /></span><!-- End: AdBrite -->HTMLBLOCK;// DO NOT PLACE ANYTHINK ON/CHANGE THE LINE ABOVE![/code]It is best to use HEREDOC syntax when echo'ing large amounts of HTML. Note if you use variables within heredoc you may need to wrap it in curly braces (example: [code=php:0]{$varname}[/code]) Quote Link to comment https://forums.phpfreaks.com/topic/35704-solved-html-in-php-if-statement/#findComment-169309 Share on other sites More sharing options...
rp2006 Posted January 25, 2007 Author Share Posted January 25, 2007 Mint, Cheers m8 :)This might-aswell get closed! Quote Link to comment https://forums.phpfreaks.com/topic/35704-solved-html-in-php-if-statement/#findComment-169344 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.