Re: Re: PHP Includes and Echoes (From the top...)

From: Date: Fri, 16 Jan 2004 13:53:56 +0000
Subject: Re: Re: PHP Includes and Echoes (From the top...)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-174793@lists.php.net to get a copy of this message
Thanks for all the tips. It's getting generally getting clearer, but I'm a little confused somewhere. Can I give you a better explanation of what I'm trying to do, along with my latest code? The pages on this site focus on various nations and states, with lots of links like this: [LOCAL] ../world/na/us/wy/index.php (World/North America/United States/Wyoming) [REMOTE] www.politix.org/world/na/us/wy/ Each page will feature several prominent instances of the name of a country or state, which I can facilitate by using 'MyName', such as the title (MyName = Canada, or Wyoming), along with several instances of its abbreviation, which is used in several URLs and in the top banner; for example, this is the top banner for Alaska: <img src="../images/banners/ak.gif" width="200" height="150" alt="" /> Below is the entire head section from the main page. Notice that it's mostly a series of variable statements ('MyName', 'MyCountry', etc.), followed by an included page (head), which is essentially the REAL head section. I inserted one of the functions you suggested - $includea1 = TRUE; - after the include, but I'm sure I did it wrong. <!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 $myname = 'MyName'; $mynickname = 'MyNickname'; $mycontinent = 'North America'; $mycountry = 'United States'; $mystate = 'MyState'; $postcode = 'wy'; $linkcontinent = '/na'; $linkcountry = '/us'; $linkstate = '/wy'; $periods = '../../../../'; $linkwebring = '/world/na/us/wy/'; include ("../../../../includes/head.php"); $includea1 = TRUE; ?> </head> * * * * * * * * * * And here's the included page: <?php $todayDate = date("m-d-Y"); echo '<title>Freedomware &gt; ' . $statename . '</title>'; echo '<meta name="description" content="' . $statename . ' versus Microsoft" />'; echo '<meta name="keywords" content="' . $statename . ' versus Microsoft" />'; echo '<meta name="mssmarttagspreventparsing" content="true" />'; echo '<meta http-equiv="content-Type" content="text/html; charset=iso-8859-1" />'; echo '<meta name="author" content="David Blomstrom" />'; echo '<script src="' . $periods . 'js/swapclass.js" type="text/javascript"></script>'; echo '<script src="' . $periods . 'js/ss.js" type="text/javascript"></script>'; echo '<script language="JavaScript" type="text/JavaScript"> <!-- function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } //--> </script>'; echo '<link href="' . $periods . 'css/a1.css" rel="stylesheet" type="text/css" />'; if ($includea1) echo '<link href="' . $periods . 'css' . $linkcontinent . '/a1.css" rel="stylesheet" type="text/css" />'; echo '<link href="' . $periods . 'css/na/north.css" rel="stylesheet" type="text/css" />'; echo '<link href="' . $periods . 'css/themes/peace.css" rel="alternate stylesheet" type="text/css" title="Peace" />'; echo '<link href="' . $periods . 'css/themes/war.css" rel="alternate stylesheet" type="text/css" title="War" />'; echo '<link rel="SHORTCUT ICON" href="../../../../us/aaa/favicon.ico" />' ?> Note that two of my style sheets are named css/a1.css and css/na/a1.css (na is short for North America). Maybe I should rename the second a1 to avoid confusion, though I'd prefer to tackle it head on and learn how to deal with this situation. (Does $includea1 = TRUE; refer to css/a1.css or css/na/a1.css?) So here's what I have at present: * * * * * * * * * * The first line denotes style sheet css/a1.css, preceded by ". $periods .", which can be replaced by ../../ or ../../../, depending on the folder level: echo '<link href="' . $periods . 'css/a1.css" rel="stylesheet" type="text/css" />'; * * * * * * * * * * The second line denotes style sheet css/na/a1.css, preceded by "if ($includea1)," which I'm probably using incorrectly: if ($includea1) echo '<link href="' . $periods . 'css' . $linkcontinent . '/a1.css" rel="stylesheet" type="text/css" />'; Note, also, that I inserted ". $linkcontinent .", which will be replaced by na/ (North America) on this particular main page. In summary, it looks like I need to fix two things: MAIN PAGE $linkwebring = '/world/na/us/wy/'; include ("../../../../includes/head.php"); $includea1 = TRUE; ?> </head> INCLUDED PAGE echo '<link href="' . $periods . 'css/a1.css" rel="stylesheet" type="text/css" />'; if ($includea1) echo '<link href="' . $periods . 'css' . $linkcontinent . '/a1.css" rel="stylesheet" type="text/css" />'; echo '<link href="' . $periods . 'css/na/north.css" rel="stylesheet" type="text/css" />'; * * * * * * * * * * I hope that isn't too confusing. It's actually becoming a lot clearer for me; I'm just temporarily confused. Thanks! * * * * * * * * * * I wrote,
? Holy cow, this gets simpler all the time.>>
? 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 ("")?
On 15 January 2004 22:39, 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)
}
Mike Ford wrote, 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.) I wrowte:
I have a couple more questions, though. First, how do I turn this exclude function off on a page where I do NOT want to ban style sheet na/a1? I tried deleting the following on the main page: if($pagetoshow == 'withouta1'){
    $includea1 = FALSE;
}else{
    $includeaa1 = TRUE; //(or false depending)
} Then I changed TRUE and FALSE in various combinations, but it didn't work.
Mike Ford wrote,
Simple -- if you have a page where you want a1 to be unconditionally included, set the variable to TRUE unconditionally: $includea1 = TRUE; Similarly, if you want it to be unconditionally blocked: $includea1 = FALSE; The include file will test the value of $includea1 as before, and include it or not as you've specified.


« previous php.general (#174793) next »