Jump to content

HELP!!


supermancody

Recommended Posts

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!!!!!!!

 

Link to comment
Share on other sites

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!

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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