RE: [PHP] Re: PHP Includes and Echoes in Head Sections and Search Engines

2004-01-16 Thread Ford, Mike [LSS]
On 15 January 2004 22:39, Luke wrote:

 ? Holy cow, this gets simpler all the time. Pretty soon, there'll be
 ? nothing left on my page but PHP includes and echo functions! ?
 ? Does this cut down on a website's file size? In other
 words, are the php
 ? includes effectively inactive when no one's viewing your main pages,
 ? leaving them empty of the included pages?
 
 Well in a way yes, it wont cut down the transfer bandwitdth,
 but because you
 are reusing the same files over again, this will take up less
 disk space on
 your
 server. But the same amount of data is transferred when a
 user views the
 page (as you can see from view-source)
 
 ? But suppose there's a certain page where I don't want the
 style sheet in
 ? the middle - the one I named MIDDLE. Is there a way to mark
 it in the
 ? include page, then instruct the main page to either not import it or
 ? replace it with nothing ()?
 
 youd have to use a variable, so in the main page do the following
 
 if($pagetoshow == 'withoutmiddle'){
 $includemiddle = FALSE;
 }else{
 $includemiddle = TRUE; //(or false depending)
 }

Euch! Very long-winded and inefficient.  Much better is:

   $includemiddle = $pagetoshow!='withoutmiddle';

 
 and in the include do this:
 
 if($includemiddle == TRUE){

Likewise -- this can be written more efficiently and more readbly as simply:

   if ($includemiddle)

(Since $includemiddle will be TRUE or FALSE, you can use it directly in the
if () -- retrieving its value and  comparing it against TRUE gives TRUE if
$includemiddle is, er, TRUE, and FALSE if it's FALSE, so doing the
comparison just wastes CPU time to reproduce the value you first thought
of.)

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP Includes and Echoes in Head Sections and Search Engines

2004-01-15 Thread Luke
hi

Very simple problems, good to see ur getting the hang of it :)
the first is, you have defined your variables after you include the page, so
that the echo is outputting a blank variable...

so instead of:

?php include (../../../../includes/state/head.php); ?
meta name=mssmarttagspreventparsing content=true /
?php include (../../../../includes/javascript.php); ?
?php include (../../../../includes/stylesheets.php); ?
?php
$statename = 'Alaska';
$postcode = 'ak';
$linkcode = 'world/na/us/ak';
?

make it

?php
$statename = 'Alaska';
$postcode = 'ak';
$linkcode = 'world/na/us/ak';
php include (../../../../includes/state/head.php);
echo 'meta name=mssmarttagspreventparsing content=true /';
include (../../../../includes/javascript.php);
include (../../../../includes/stylesheets.php);
\?

i just changed the opening and closing tags a little (you didnt need so
many) but the main change is, now the variables come before the included
file, so that the include file can access those variables too.

echo's will work anywhere inside a ?php tag so, it will always output
something to the screen

no problems with search engines, if you use the meta tags and stuff u
usually use, itll work fine

javascript, stylesheets and stuff... the only thing to remember is all the
stylesheet files, and javascript files are relative to the final page
location, not to the include file location, but other than that its the same
as normal

hope that clears it up a bit :)

-- 
Luke
Freedomware [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I'm having a blast with PHP includes and echo functions; I never dreamed
 they could be so simple and effective. But I have a couple questions
 relating to head sections and search engines.

 Consider the following html code:

 !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; xml:lang=en lang=en
 head
 ?php include (../../../../includes/state/head.php); ?
 meta name=mssmarttagspreventparsing content=true /
 ?php include (../../../../includes/javascript.php); ?
 ?php include (../../../../includes/stylesheets.php); ?
 ?php
 $statename = 'Alaska';
 $postcode = 'ak';
 $linkcode = 'world/na/us/ak';
 ?
 /head
 body

 Welcome to ?php echo $statename ?!

 * * * * * * * * * *

 And here's the html code from the include named head.php:

 ?php
 $todayDate = date(m-d-Y);
 ?
 titleFreedomware gt; ?php echo $statename ?/title
 meta name=description content=?php echo $statename ? versus
 Microsoft /
 meta name=keywords content=Alaska, Microsoft, Microshaft, Linux,
 Bill Gates, corporate corruption /

 * * * * * * * * * *

 I discovered that includes will apparently work just about anywhere, but
 echo functions apparently don't work with the title tag and meta tags;
 at least, I can't see the word Alaska in those locations when I click
 View Source in my browser.

 So I wondered if there IS a way to make echo functions work in meta tags.

 Also, do you know if text derived from includes causes any problems with
 search engines? My guess is no, because I can see the included words
 just fine when I click View Source.

 Along similar lines, I wondered if there might be potential pitfalls if
 you import links to style sheets and javascripts as includes. Everything
 seems to work just fine so far.

 Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP Includes and Echoes in Head Sections and Search Engines

2004-01-15 Thread Freedomware
i just changed the opening and closing tags a little (you didnt need so
many) but the main change is, now the variables come before the included
file, so that the include file can access those variables too.
Holy cow, this gets simpler all the time. Pretty soon, there'll be 
nothing left on my page but PHP includes and echo functions!

Does this cut down on a website's file size? In other words, are the php 
includes effectively inactive when no one's viewing your main pages, 
leaving them empty of the included pages?

Here's another question. I'm replacing the ../ URL prefixes with the 
echo name $periods, so I can use these includes in pages on several 
levels, such as geobop/one and geobop/one/two, simply replacing $periods 
with ../../ or ../../../.

Below is some code from my include page:

link href=?php echo $periods ?css/a1.css rel=stylesheet 
type=text/css /
link href=?php echo $periods ?css/MIDDLE.css rel=stylesheet 
type=text/css /
link href=?php echo $periods ?css/na/rockies.css rel=stylesheet 
 type=text/css /

But suppose there's a certain page where I don't want the style sheet in 
the middle - the one I named MIDDLE. Is there a way to mark it in the 
include page, then instruct the main page to either not import it or 
replace it with nothing ()?

Thanks.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP Includes and Echoes in Head Sections and Search Engines

2004-01-15 Thread Luke

? Holy cow, this gets simpler all the time. Pretty soon, there'll be
? nothing left on my page but PHP includes and echo functions!
?
? Does this cut down on a website's file size? In other words, are the php
? includes effectively inactive when no one's viewing your main pages,
? leaving them empty of the included pages?

Well in a way yes, it wont cut down the transfer bandwitdth, but because you
are reusing the same files over again, this will take up less disk space on
your
server. But the same amount of data is transferred when a user views the
page (as you can see from view-source)

? But suppose there's a certain page where I don't want the style sheet in
? the middle - the one I named MIDDLE. Is there a way to mark it in the
? include page, then instruct the main page to either not import it or
? replace it with nothing ()?

youd have to use a variable, so in the main page do the following

if($pagetoshow == 'withoutmiddle'){
$includemiddle = FALSE;
}else{
$includemiddle = TRUE; //(or false depending)
}

and in the include do this:

if($includemiddle == TRUE){
echo 'link href=' . $periods . 'css/MIDDLE.css rel=stylesheet
type=text/css /';
}


just a side point, you may be better of doing your html code with echos, as
you have a few variables in there.. eg
?php
echo 'link href=' . $periods . 'css/a1.css rel=stylesheet
type=text/css /';

if($includemiddle == TRUE){
echo 'link href=' . $periods . 'css/MIDDLE.css rel=stylesheet
type=text/css /';
}
echo 'link href=' . $periods . 'css/na/rockies.css rel=stylesheet
type=text/css /';
?

and if you are echoing a variable, quotes around it arent needed

you can just use
echo $variable;
instead of
echo $variable;

Luke

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP Includes and Echoes in Head Sections and Search Engines

2004-01-15 Thread Freedomware
I wrote:

? But suppose there's a certain page where I don't want the style sheet in
? the middle - the one I named MIDDLE. Is there a way to mark it in the
? include page, then instruct the main page to either not import it or
? replace it with nothing ()?


Luke wrote:

youd have to use a variable, so in the main page do the following

if($pagetoshow == 'withoutmiddle'){
$includemiddle = FALSE;
}else{
$includemiddle = TRUE; //(or false depending)
}
and in the include do this:

if($includemiddle == TRUE){
echo 'link href=' . $periods . 'css/MIDDLE.css rel=stylesheet
type=text/css /';
}




I think I just about have it. But I replaced the middle in both our 
examples with the page I'm REALLY trying to exclude - na/a1.

Most pages on my site will have the following two style sheets:

link href=../../../../css/a1.css rel=stylesheet type=text/css /
link href=../../../../css/na/a1.css rel=stylesheet type=text/css  /
But some will only have the first one:

link href=../../../../css/a1.css rel=stylesheet type=text/css /



So I applied your example to the head section of my main page and came 
up with this:

!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; xml:lang=en lang=en
head
?php
$statename = 'Alaska';
$postcode = 'ak';
$linkcode = 'world/na/us/ak';
$periods = '../../../../';
include (../../../../includes/state/head.php);

if($pagetoshow == 'withoutna/a1'){
$includena/a1 = FALSE;
}else{
$includeana/a1 = TRUE; //(or false depending)
}
?



* * * * * * * * * *

And below is all the code from the included page, head.php:

?php
$todayDate = date(m-d-Y);
if($includeana/a1 == TRUE){
echo 'link href=' . $periods . 'css/na/a1.css rel=stylesheet
type=text/css /';
}
echo 'titleFreedomware gt; $statename/title';
echo 'meta name=description content=ZXZX versus Microsoft /';
echo 'script src=' . $periods . 'js/swapclass.js 
type=text/javascript/script';

echo 'link href=' . $periods . 'css/a1.css rel=stylesheet 
type=text/css /';
echo 'link href=' . $periods . 'css/na/a1.css rel=stylesheet 
type=text/css /';
if($includena/a1 == TRUE){
echo 'link href=' . $periods . 'css/na/a1.css rel=stylesheet 
type=text/css /';
}
echo 'link href=' . $periods . 'css/na/rockies.css rel=stylesheet 
type=text/css /';
?

I haven't been able to exclude na/a1 yet, but everything in the included 
page was working right up until about the end, when I did something that 
knocked it out of action.

Also, I got a division by zero error. Is that something that's caused 
by a mistake I made in writing code? I read a couple articles online 
that suggested it's a problem with Apache.

Finally, is there a way to validate php, similar to validating pages 
for html and css?



and if you are echoing a variable, quotes around it arent needed

you can just use
echo $variable;
instead of
echo $variable;
I got a little confused; did I do it right in the example above?

Thanks!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP Includes and Echoes in Head Sections and Search Engines

2004-01-15 Thread Freedomware
Oops, I spotted some big errors in my included page already. Here's the 
new page:

?php
$todayDate = date(m-d-Y);
echo 'titleFreedomware gt; $statename/title';
echo 'meta name=description content=ZXZX versus Microsoft /';
echo 'script src=' . $periods . 'js/swapclass.js 
type=text/javascript/script';
echo 'link href=' . $periods . 'css/a1.css rel=stylesheet 
type=text/css /';
if($includena/a1 == TRUE){
echo 'link href=' . $periods . 'css/na/a1.css rel=stylesheet 
type=text/css /';
}
echo 'link href=' . $periods . 'css/na/rockies.css rel=stylesheet 
type=text/css /';
?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php