Note: This isn't a question... this is just some details on something fun I just did for the folks who are interested in what PHP can do ( http://www.php4.org/ ) Ok, I'm working on a glossary document on one of my websites. As I define terms, I have to, in turn, add more terms to be defined. (For example, when you define the term "browser", you need to explain what the words "hypertext", "client" and "server" mean. :) ) The page I'm working on is generated in PHP, and to create a term, I simply call a PHP function I wrote which includes the term name and the definition. <dl> <? my_define("Term 1", "The meaning of term 1 is blah blah blah..."); ?> <? my_define("Term 2", "The meaning of term 2 is foo bar baz..."); ?> <? my_define("Term 3", "The meaning of term 3 is x y z..."); ?> </dl> The "my_define()" PHP function creates a definition ("<dt>" / "<dd>" pair) containing the term, nice and pretty in bold, followed by the definition. An aside... To handle cross-references, I created a function which allowed me to list the term I was referencing, as well as the text to display as the link. This is useful not just for things like: HTTP See: _Hypertext_Transfer_Protocol_ but also for things like: ...such as _modems_. ( With that link ref'ing to "Modulator/Demodulator" ) So, in "my_define()", I also put an "<a name>" tag around the term itself, so that the page has a bunch of internal anchors available. If you go to: http://www.thesite.com/glossary/#Computer ...it'll automagically scroll to the definition of "Computer." To create references, I needed to create a true function (something that returns a string, rather than just prints some HTML out on the page). This is because the references are part of the definition string being sent to my "my_define()" function. Example: <? my_define("Modem", "A device you connect to a " . my_ref("Telephone", "phone") . " to talk to another computer."); ?> In PHP, the "."'s concatenate strings. (So "a" . "b" . "c" is the same as "abc") In the above example, the definition will say "...connect to a phone to...", where the word "phone" is a hyperlink to the definition of the term "Telephone". :) Anyway, back from my aside.... Like I was saying, as I define terms, I find more and more terms need to be added to my glossary. The page is getting a bit big, so I thought "Gee, it'd be nice if I could just look at the terms which NEED defining." Well, I can! By sending an URL-encoded name/value pair to the PHP page (ie, similar to when you fill out an HTML form and submit it), I can check to see whether the user wants to see ALL terms, or just undefined ones. (In other words, ones where I sent an empty string to "my_define()" as the second argument). It goes something like this: http://www.mysite.com/glossary/ <- show all terms http://www.mysite.com/glossary/?undef=1 <- show only undefinied In the "my_define()" script, I do this simple test: If "undef" isn't set to 1, _OR_ if the definition being sent to me isn't empty, show the term. Otherwise, don't. In PHP, it looks like: <?php function my_define($term, $definition) { global $undef; /* Bring variable back into scope here */ if ($undef == 0 || $undef == "...") { print "<dt><a name=\"$term\"><font color=\"#FFFFFF\">" . "<b>$term</b></font></a\></dt>\n"; print "<dd>$definition<p></dd>\n"; } } ?> I can, of course, add an HTML link on the page which calls the PHP document again with "undef=1" set. Even cooler, I can make it like a toggle switch! If we're ALREADY looking at only the undefined terms, make the link go back to the document without "undef=1", and label the link "Show all terms". If we're NOT looking at only the undefined terms, create a link with "undef=1", and label the link something like "Show only undefined terms." In PHP, at the bottom, I added: <? if ($undef == 0) { ?> You can also <a href="index.php3?undef1">show only terms which are currently undefined</a>. <? } else { ?> <a href="index.php3">Switch back to full view.</a> <? } ?> Cool, huh!? :) PHP rocks! -bill! (rediscovering how entirely awesome PHP's online documentation is, thanks to the ability for visitors to add notes)
