Jump to content

[SOLVED] HTML in PHP if Statement


rp2006

Recommended Posts

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.
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 :)
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])

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.