包含html页面中的PHP echo或print语句的样式

Part of my validation script spits error codes depending on the error. It includes displaying an html error page. The statements that print or echo out on the error page always push the page down and also seem to affect some odd things like font size etc. It by default always displays the echo statements at the top of the page in the center. Is there a way I can style this? I would like the error message to display at a certain areas within the html?

if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
    echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
    echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
    echo "Email Address is a required field. Please enter it below.<br />";
}
include 'error_reg.htm'; 
exit(); 
}

Actually its quite straightforward, in your echo, just add/wrap the html tag you desire on that message. The styling can be just as anything as you want it to look. And the placement of that error is also entirely up to you.

Here is a super basic example:

<!-- or just use an external css file -->
<style type="text/css">
.error-box {
    color:#555;
    font-family:Tahoma,Geneva,Arial,sans-serif;font-size:11px;
    padding:10px 10px 10px 36px;
    margin:10px;
    background-color: #ffecec;
    border:1px solid #f5aca6;
    width: 300px;

}
</style>
<?php
$first_name = '';
if(!$first_name){
    echo "<div class='error-box'>First Name is a required field. Please enter it below.</div>";
}
?>

please, do the following in php:

echo "<p class='my_error'>Email Address is a required field. Please enter it below.</p>";

and then in external .css file (or in style tags in the head of your page):

.my_error{
color: red;
font-size: 14pt;
/*... and whatever you want*/
}

The easiest way (however, considered a bad practice) is to use inline styles, like:

echo "<p style='color:#FF0; font-size:14pt'>Some message</p>";

Please use this approach only if your application is really small, while this mixup of styles and html greately complicates maintaining.

it would not be a lot of work at all.

echo "<p class="whatever">;

echo "your error messages";

echo "</p>";

You're basically just ecapsulating the error message with html tag so you are able to style it using css with

whatever {
    font-size: 12px
}

You can do it by adding the PHP scripts inline with your HTML. I don't know what's in your error_reg.htm file though.

<body>
<div id="error_status">
<?php
if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
    echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
    echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
    echo "Email Address is a required field. Please enter it below.<br />";
}
include 'error_reg.htm'; 
exit(); 
}
?>
</div>
</body>