Jump to content

How can I add html tags in php as a variable?


jdock1

Recommended Posts

How can I add html tags in php as a variable?

 

For example, for some reason my code gives me a header error if I use html before the php tags.

 

I just need to add the style in there.

 

I was wondering how I could add a style of any html tag within php as a variable??

 

Like I was thinking like

 

<?php
$style = "<style>

div.error {
border: 1px dashed #660000;
background: #fee;
color: #660000;
}
</style>";

echo $style;


?>

But that would probably just print out the code... how can I make it so it wont print out on screen and I can actually use the style?

 

Sorry for the noob question... im kind of an intermeddiate php programmer but the noobs questions still seem to never go away!

Oh okay I got it, kind of. I got it to apply the style and echo the html tags. Its pretty sloppy tho. Its like this;

 

$html = "<html>";
$head = "<head>";
$endhead = "</head>";
$endhtml = "</html>";
$style = "<style>div.errors {
border: 1px dashed #660000;
background: #fee;
color: #660000;
}</style>";
... // blah blah blah
if($current_time - $blocked_time > 3600*24) //24 hours past
        {
            $str_sql = "delete from ".$db_table." where ipaddress='".$surfer_ip."'"; 
            mysql_query($str_sql); 
            $str_sql = "insert into ".$db_table." (ipaddress, surf_index) values('".$surfer_ip."', 1)";
            mysql_query($str_sql);   
        }
        else
        {
        echo "$html";
        echo "$head";
        echo "$style";
        echo "$endhead";
            die ("<div align='center' class='errors'>You have accessed this page too many times. To regain access, purchase a license or wait 24 hours.</div>");
            echo "$endhtml";
        }
    }  

 

Is there an easier, cleaner way to do this??

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.