Jump to content

Indent style question


hostfreak

Recommended Posts

I was wondering, if your coding and going in between php and html. Do you stick with your indent style your using within your php tags when your doing your html. For example:
[code]
<?php
include("include/session.php");

if ($session->logged_in)
{
include("include/constants.inc");

$connection = mysql_connect("$server","$user","$password"); 
$db = mysql_select_db("$database", $connection);   
$sql = mysql_query("SELECT * FROM settings"); 
while ($row = mysql_fetch_array($sql))
{
$title = $row["title"];
$companyname = $row["companyname"];
$adminemail = $row["adminemail"];
}
?>
<html>
<head>
<title><?php echo "$companyname - $title"; ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen" name="style">
@import "style.css";
@import "print.css";
</style>
</head>
<body>
<div id="top">
<div id="logo">
<?php echo "$companyname"; ?>
</div>
<div id="slogan">
<?php echo "$title"; ?>
</div>
</div>
</body>
</html>
<?php
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
echo "You are not authorized to view this page! An email has been dispatched to the administrators to inform them of your whereabouts!<br>";
echo "Your IP address: <b>$ip</b> , has been recorded and will be reported to the law if this happens again!";
}
?>
[/code]

Or would you indent the html differently? I usually don't tab, only 4 white spaces. But, to make things clearer in this example I used tab. I know it probably has a lot to do with personal preference, but if there is a certain standard / style for html I would like to know. Other wise I will probably continue doing the same style as with my php code. Sometimes though, if the html code goes into a lot of tags, it will look sloppy. Maybe it would be best in situations like that, to include the php from it's own file? So it doesn't have to embed into all the tags?
Link to comment
Share on other sites

code wise, any code should follow the indenting of it's parent, but html should follow the output structure, so I would start <html> to left and not follow the PHP code logic, because to me they they are not the same, and in all reality don't belong there in the first place! Sure on a forum like this, most questions are about in and out processing logic, but it's not the best way for bigger applications where code logic should never be mixed with flush type logic, because it makes the code terrible to manage.

me!
Link to comment
Share on other sites

This isn't really an answer to your question, but I use Smarty templates.  Then the HTML and PHP are in separate files, and there is no question of how to indent the mixed code.

The general rule I follow when deciding on how to indent is "Does it make the structure clear?"  If it does, great.  If it doesn't, try some other method of indenting.  Eventually you'll hit on something which makes it look nice.  You might need to change the indenting style for different pages because they have a different structure, rather than using one global rule for all pages.
Link to comment
Share on other sites


In the below example the text is aligned to the center of the page within a paragraph with the color red and the text is transformed to uppercase letters and the first line of letters are indented.

You can only indent the first line of text and select the px needed

Text Indent Example

p
{
color: red;
align-text:
center;
text-transform:
uppercase;
text-indent:
25px;
}
Link to comment
Share on other sites

Thanks guys, all really good responses. I am familiar with css (not the best, still learning). I was just curious as to whether I should follow the same indention style when going between php and html.

I think if it works without looking sloppy, I'll follow my normal indention style. Otherwise I'll probably end up making some changes to make it look good (which is like what btherl suggested). Once again, thanks.
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.