supermancody Posted October 22, 2007 Share Posted October 22, 2007 I'm new to PHP and used to program using HTML. THis is the code I have, which works fine in HTML, yet not in PHP. Could someone please help. <?php echo"<style>" ."#bg {background-image: url(bg.gif); width: 10px; height: 30px;}" ."</style>" ."<div id=\"bg\">" ."</div>"; ?> THANKS!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/74352-help/ Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 <?php echo" <style> #bg {background-image: url(bg.gif); width: 10px; height: 30px;} </style> <div id=\"bg\"> </div>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74352-help/#findComment-375662 Share on other sites More sharing options...
nafetski Posted October 22, 2007 Share Posted October 22, 2007 Just to give you a bit more clarification since you're new =) All echo does is output text which in turn can be parsed as HTML. If you're going to echo a style statement like that, you can do it one of three ways. 1) The way that was listed above. It looks a little awkward tho, since you have the open quote before the <style> tag, and the end quote at the end of the </div> tag. After the end quote of any echo statement, you have to put a semicolon. 2) Echo each line. This of course isn't reccomended, since it's slow and clunky...but. <?php echo "<style>"; echo ".bg {background-image: url(bg.gif); width: 10px; height: 30px;}"; echo "</style>"; echo "<div id = "bg">"; echo "</div>"; ?> 3) Or, the way that I like doing it a lot of the time...just break out of php! Say you've got some php you have to use... <?php $hello = "Hello! I am a pointless string"; ?> <td><?php echo $hello; ?></td> Can get awkward for small things, but if you're going to output a lot of HTML it's your best bet. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/74352-help/#findComment-375727 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.