Dates & String handling in PHP


10/8/02
 

Dates in PHP

I consulted the section on dates and calendar functions in the PHP Manual and discovered that I can use this...
echo date ("d/m/y");   // echoes e.g. 12/08/02
...which should make it very easy to compare the expiry date set by the user in an Expiry Checker field within a web page to today's date.

The "parse_str" function

I then looked up the string handling section and found a very useful function called "parse_str" that will extract the chunks from any expression in this form...
$expression = "str1=testing&str2=hello&str3=123"
I tried this simple test script...
<?php

// A script to test the "date" and "parse_str" functions

// author = Martin Bush, South Bank University
// date = 10th August 2002
// filename = testing-parse_str.php3
// version = 1.1
// history = -

echo "Just checking that the date function works...<p>";
echo date ("d/m/y");
echo "<p>That should have echoed 10/08/02<p>";

echo "Now to test that the parse_str function works...<p>";
$request = "expires=15/08/02&email=bushm@sbu.ac.uk&reminder=any string";
parse_str($request);
echo $reminder . "<br>";
echo $email . "<br>";
echo $expires;

?>
 
...and it worked perfectly. This means that instead of using the syntax which I had in mind initially (back to relevant page) for Expiry Checker fields it might be easier if I changed it to something like this instead:
<!-- Expiry Checker: expires=15/08/02&email=bushm@sbu.ac.uk&reminder=New MSc? -->
This is actually better than the solution I had in mind initially, because instead of restricting users to having to specify one of several keywords it allows them the option of putting in any message that will remind them of what it is they are supposed to update when the time comes.
 
 

<<contents ^top^ next>>