Here are a couple of useful tips:
Simple framework:
All included files are prefixed with an underscore so they easily grouped and sorted.
Toggle included files by changing 0 to 1 (false to true)
PHP Code:
<?php /* index.php */
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<title><?php echo $title;?>
<head>
<?php if(0) { include '_heading-001.php';} ?>
<?php if(0) { include '_heading-002.php';} ?>
<style type='text/css'>
body {background-color:#fee}
</style>
</head>
<body>
<div class='container'>
<div class='box_left'>
<?php if(0) { include '_box_left-001.php';} ?>
<?php if(0) { include '_box_left-002.php';} ?>
<?php if(1) { include '_box_left-003.php';} ?>
</div>
<div class='box_content'>
<?php if(0) { include '_box_content-001.php';} ?>
<?php if(1) { include '_box_content-002.php';} ?>
<?php if(0) { include '_box_content-003.php';} ?>
</div>
<div class='footer'>
<?php if(1) { include '_box_footer-001.php';} ?>
<?php if(0) { include '_box_footer-002.php';} ?>
<?php if(0) { include '_box_footer-003.php';} ?>
</div>
</div><?php /* container */?>
</body>
</html>
Second:
Debug function which saves typing and formatted
Works for all variables, integers, strings, object, etc
Could also use var_dump(...) instead of print_r(...);
PHP Code:
function fred($a) {echo "<pre>"; print_r($a); echo '</pre>';}
# usage:
$a = array('John', 'Jack', 'Fred', ' Jimmy');
fred( $a );
echo __FILE__;
die;
# output formatted nicely
John
Jack
Fred
Jimmy
Saves typing and should also be in a _config.php file
PHP Code:
# does not produce error if already defined
# produces shortcut for <br />'
defined('jj') ?: define('jj', '<br />');
#usage:
echo jj,jj,jj;
# only requires a single file for both LOCALHOST and ONLINE
# prevents overwriting files with same names
defined('LOCALHOST') ?: define('LOCALHOST', 'localhost' == $_SERVER['SERVER_NAME']);
# usage:
if(LOCALHOST)
{
# MySQL localhost connection details
# show debug stuff
}
else
{
# MySQL ONLINE connection details
# show online stuff
}
Bookmarks