[NTLUG:Discuss] PHP Code for Lazy HTML Coders
Jason Ferguson
jferg3 at swbell.net
Mon Dec 31 15:32:41 CST 2001
I made some changes to my original code based on Paul's suggestions. I
decided to keep the echo statements, though I understand and agree with
what he was saying. By keeping the echo statements, I find my html code
to be a tad more readable.
Anyhow, thanks for the help Paul. I submit the following code to the
list for anyone who needs such a thing.
Jason
<?
function htmlheader($html="")
{
// Written by Jason Ferguson, (c) 2001
// With a great deal of help from Paul Ingendorf
// Use example:
//
// $html->title="My Page";
// $html->stylesheet="stylesheet.css";
// $html->meta=ARRAY(
// ARRAY("NAME","Keywords","CONTENT","Jason stuff"),
// ARRAY("HTTP-EQUIV","Expires","CONTENT","Wed, 2 Jan 2001 00:00:01
GMT")
// );
//
// Version history:
// 0.1: It works for <TITLE> and <META>, but forgot to do style sheets.
Doh!
// 0.2: Okay, okay, I added the <LINK> tag for stylesheets. Relative and
// absolute URLs to the stylesheet should work. Just put "" if there is
no
// stylesheet
// 0.3: Based on suggestions, I rewrote the code to use an onject,
meaning I
// no longer needed all those func_num_args and other functions to check
all
// that stuff that was originally passed
echo "<html>\n";
echo "<head>\n";
// First, we see if a title needs to be set. If so, we generate the
<title> tag
if (isset($html->title))
{
echo "<title>$html->title</title>\n";
}
else
{
echo "<title></title>";
}
// Second, We check if there is a stylesheet and generate the tag if
necessary
if (isset($html->stylesheet))
{
echo "<LINK REL=\"stylesheet\" HREF=\"$html->stylesheet\">\n";
}
// Next. we check the passed meta tage info. This is supposed to be in
the form of
// an array. The count of the meta tags is checked to see if its evenly
divisable
// by 4, since there are four parts to the META tag (attribute=value,
attribue=value)
if (isset($html->meta))
{
echo "<META ";
for ($i=0; $i<=count($html->meta);$i++)
{
if (count($html->meta)%4==0)
{
echo "$html->meta[$i]=\"";
$i++;
echo "$html->meta[$i]\" ";
$i++;
echo "$html->meta[$i]=\"";
$i++;
echo "$html->meta[$i]\">\n";
}
else
{
echo "Incorrect number of META tag arguments (4 arguments per meta
tag).";
}
}
}
// Finally, we close the <head> tag.
echo "</head>\n";
}
?>
On Mon, 2001-12-31 at 11:24, Paul Ingendorf wrote:
> 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.
>
(snip)
>
> --
> -->> 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>
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://ntlug.org/pipermail/discuss/attachments/20011231/9cd27f14/attachment.bin
More information about the Discuss
mailing list