l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
September 2: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2001 Dec 30 17:01

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] PHP fun!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] PHP fun!


  • Subject: Re: [vox-tech] PHP fun!
  • From: "Jay Strauss" <jjstrausMAPSs@yahoo.com>
  • Date: Wed, 21 Feb 2001 05:41:57 -0800
  • References: 200102210833.f1L8XR518351@sonic.net

Why don't you use mod_perl?

Jay Strauss
jjstrauss@yahoo.com

----- Original Message -----
From: "William Kendrick" <nbs@sonic.net>
To: <vox-tech@lists.lugod.org>
Sent: Wednesday, February 21, 2001 2:33 AM
Subject: [vox-tech] PHP fun!


>
> 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)


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.