NYCPHP Meetup

NYPHP.org

[nycphp-talk] Including CSS?

Peter Sawczynec ps at pswebcode.com
Thu Jun 9 14:21:36 EDT 2005


.css and .js files can typically be included anywhere in the HTML doc and
the info will get pulled in. It is not pretty but it works.

But for clarity, in a hypothetical file such as base.php with content of:

<?php
inlcude_once(../../../head.inc.php);
include(variablebody.php);
include_once(../foot.inc.php);
?>

If the hypothetical content of head.inc.php is similar to:

<?php
$switchvar = 33;

$style1='<link rel="stylesheet" type="text/css" href="css/externalstyle.css"
title="style" />'; 
$style2='<link rel="stylesheet" type="text/css" href="css/internalstyle.css"
title="style" />'; 

($switchvar==33)? $stylechoice = $style1 : $stylechoice = $style2;

echo <<<END

<!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>$switchvar Page</title>
<meta name="Description" content="" />
<meta name="Keywords" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Expires" content="mon, 04 dec 1999 21:29:02 gmt" />
<meta http-equiv="pragma" content="no-cache" />
$stylechoice
</head>

END;

$newbodyvar = $switchvar++;
?>

Then it doesn't matter at all where the file called head.inc.php is
physically located because the .css file won't get included until
PHP has composited the page and sent it down to the browser as raw HTML and
the browser will grab the .css include according to your 
true web site dir structure.

Peter



-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On
Behalf Of leam at reuel.net
Sent: Thursday, June 09, 2005 1:05 PM
To: talk at lists.nyphp.org
Subject: [nycphp-talk] Including CSS?


The first way I saw to reference a CSS file was to have it in the <head>
section, like this:

<link rel="stylesheet" type="text/css"
href="http://albasystemadmin.org/alba.css">

But since i'm using include() on some files outside the docroot, is there a
way to include the css file? Or does to have to be in the header?

ciao!

leam

_______________________________________________
New York PHP Talk Mailing List
AMP Technology
Supporting Apache, MySQL and PHP
http://lists.nyphp.org/mailman/listinfo/talk
http://www.nyphp.org





More information about the talk mailing list