[NTLUG:Discuss] PHP Code for Lazy HTML Coders

Paul Ingendorf pauldy at wantek.net
Mon Dec 31 11:24:42 CST 2001


For some added security to those scripts I would change the extension of your include file to something that is parsed if accesses directly like functions.php.  This way if someone stumble across it they don't receive all your php code.  Do this esp if you ever do any db connectivity in your functions file.  Also instead of using the echo statements you will find your code optimizes better when you use pass through more.  This is not always the case most of the time an echo s the same but for those instances where it is not I find it more beneficial to do it this way.  Also by creating an object and using an array to assign your meta tags it will make it a lot easier when creating them.  See below.

<?
function htmlheader( $html = "" ) {
  if ( isset($html->title) ) {
?>
<html>
<head>
<title><?=$html->title?></title>
<?php
  }
//  Check if css is set if not just skip it
  if ( isset($html->css) ) {
?>
<LINK REL="Stylesheet" HREF="<?=$html->css?>">
<?php
  }
  if ( isset( $html->meta ) ) {
    for ( $i = 0;$i < count($html->meta); $i++ ) {
      if ( count($html->meta[$i]) == 4 ) {
?>
<META <?=$html->meta[$i][0]?>="<?=$html->meta[$i][1]?>" <?=$html->meta[$i][2]?>="<?=$html->meta[$i][3]?>">
<?php
      } else {
?>
<!-- The meta tag was broken. Check arguments. -->
<?php
        for ( $x = 0; $x < count($html->meta[$i]); $x++ ) {
?>
<!-- $html->meta[<?=$i?>][<?=$x?>] = <?=$html->meta[$i][$x]?> -->
<?php
        }
      }
    }
  }
?>
</head>
<?php
}
// example of how to execute.
$html->title = "My Page";
$html->css = "style.css";
$html->meta = ARRAY(
  ARRAY("NAME","keywords","CONTENT","Jason, misc stuff"),
  ARRAY("NAME","keywords","CONTENT","PHP coding example")
);
htmlheader($html);
?>

-- 
-->> mailto:pauldy at wantek.net
-->> http://www.wantek.net/
Running ....... Cos anything else would be a waste...
`:::'                  .......  ......
 :::  *                  `::.    ::'
 ::: .::  .:.::.  .:: .::  `::. :'
 :::  ::   ::  ::  ::  ::    :::.
 ::: .::. .::  ::.  `::::. .:'  ::.
.:::.....................::'   .::::..


-----Original Message-----
From: discuss-admin at ntlug.org [mailto:discuss-admin at ntlug.org]On Behalf
Of Jason Ferguson
Sent: Monday, December 31, 2001 8:27 AM
To: NTLUG
Subject: [NTLUG:Discuss] PHP Code for Lazy HTML Coders


I wanted to share the following PHP code I cobbled together so that if
anyone else had a use for it, they are welcome to it.

I created this code because after creating what feels like MILLIONS of
web pages over the last several years, Im sick of the first section: the
<HTML> declaration and the <HEAD> section. Most of that is pretty
repetitive, so I created a function to automate that section. Instead of
all the repetitive type for each page, all I do is start each document
like this:

(Note: for the real HTML purists, I handle the <DOCTYPE> by including a
text file with only the DOCTYPE in it. That way I can change one small
file and all my pages are updated).

<?
	include("doctype.txt")
	include("functions.inc");
	htmlheader(title, stylesheet location, meta tag stuff);
?>
 

<sniped for brevity>





More information about the Discuss mailing list