Jump to content


Photo

Indent style question


  • Please log in to reply
6 replies to this topic

#1 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 19 October 2006 - 01:52 AM

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:
<?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!";
}
?>

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?

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 19 October 2006 - 01:53 AM

I don't tab html; I just use lots of new lines :P.
Why doesn't anyone ever say hi, hey, or whad up world?

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 October 2006 - 02:13 AM

If you want to use php within html then your need to learn css as css can provide outstanding results.

saying that looking at your code looks good to me.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 19 October 2006 - 02:36 AM

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!

#5 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 19 October 2006 - 02:43 AM

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.

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 October 2006 - 02:51 AM


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;
}
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 19 October 2006 - 10:12 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users