PDA

View Full Version : Sloppyness


owner
10-09-2007, 08:44 PM
Hello,

I am trying to make my own little portal type of thing, but I am mixing my code with php and html so everything is sloppy, hard to find, and just looks bad.
Example:

Here is part of my header file:

<?php
session_start();
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">";
include ('./includes/backend.php');

$backend = new backend();
$backend->load_language('lang_global'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $backend->lang['page_title']; echo $backend->lang['title_sub_page']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="I removed the actual link to the css on purpose here" rel="stylesheet" type="text/css" />
</head>What would be an easy alternative to really organize out everything?

Thanks everyone,
-Owner

davidj
10-09-2007, 08:54 PM
<?php

session_start();
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1?\">";
include ('./includes/backend.php');

$backend = new backend();
$backend->load_language('lang_global');

$title = $backend->lang['page_title']." ".$backend->lang['title_sub_page'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="I removed the actual link to the css on purpose here" rel="stylesheet" type="text/css" />
</head>

owner
10-09-2007, 08:54 PM
Is their a way to totally eliminate all the html code?

Maybe store the html code in a file or something, then call that block of code? Or what would be a nice effective way?

davidj
10-09-2007, 09:00 PM
html is the driving code

its streamlining the PHP which is the secret. you have to utilise includes and functions.

Remember that PHP is very different from HTML and that its stripped out before being sent to the browser

Jittor
10-10-2007, 12:52 AM
Don't forget to add comments for yourself inbetween your bits of php. this will help you easly find the right code your looking for as well as help clean up your site. Davidj talks about this in his PHP tutorial. I think it's in Part 4 or 5:

http://www.dreamweaverclub.com/vtm/php-mysql-apache.php

domedia
10-10-2007, 03:30 PM
Is their a way to totally eliminate all the html code?

Maybe store the html code in a file or something, then call that block of code? Or what would be a nice effective way?

PHP template systems are built like this. Look at Smarty.