Archive for March, 2006

checking the date with php

Thursday, March 23rd, 2006

bits of the code here are taken from php.net

to check the date in php you can use a function called checkdate() but to get it working in a clever way with a form use the function below

< ?php

/**
* Checks for a valid date
*
* @param string Date in the format given by the format parameter.
* @param integer Disallow years more than $yearepsilon from now (in future as well as in past)
* @param string Formatting string. Has to be one of 'dmy', 'dym', 'mdy', 'myd', 'ydm' or 'ymd'. (Default is 'ymd' for ISO 8601 compability)
* @return array [ year, month, day ]
* @since 1.0
*/

function datecheck($date, $yearepsilon=200, $format='dmy') {
$date=str_replace("/", "-", $date);
$format = strtolower($format);
if (count($datebits=explode('-',$date))!=3) return false;
$year = intval($datebits[strpos($format, 'y')]);
$month = intval($datebits[strpos($format, 'm')]);
$day = intval($datebits[strpos($format, 'd')]);

if ((abs($year-date('Y'))>$yearepsilon) || // year outside given range
($month<1) || ($month>12) || ($day<1) ||
(($month==2) && ($day>28+(!($year%4))-(!($year%100))+(!($year%400)))) ||
($day>30+(($month>7)^($month&1)))) return false; // date out of range

return checkdate($month,$day,$year );
}

?>

this will check the variable $date.

First of all it replaces any ‘/’ symbols with ‘-’.
Using the specified format ($format) it checks to see you have 3 bits (day ,month, year).
Using the range of dates ($yearepsilon) it checks that the date is in range.
Then php’s checkdate function is used - this checks to see whether that date actuall did, or could exist.Only if everything matches will the function return true - otherwise it will return false

The checkdate function is pretty smart - it knows every day of every year between 1 and 32767 inclusive. For instance if 29/2/2000 were entered (using the day, month, year format) checkdate would return true as 2000 was a leapyear.

Using the function:

If you had a field with the name ‘date’ in your form you could set an error variable if the date was invalid, then use that error variable tell the user they’d made a mistake.

< ?php

if (datecheck($_POST['date']) == false){
$error = 1;
}
else { echo "the date is fine";}

?>

amazon ACDC review

Saturday, March 11th, 2006

The text below has been copied verbatim from the amazon.com review section for ACDC’s Back in Black - I particularly like the end sentence - the bit Amazon adds for you. I think it was in some way.

“Ten songs, three chords, smack-some-ass rock n’ roll, August 6, 1998
Reviewer: Rodems@aol.com (Tampa, Florida) - See all my reviews
AC-DC was in disarray when this album came out: The previous lead singer had died of alcohol poisoning. Most said the band’s best music had been played. Nobody expected much.

This album was a monster. Considering the tired and irritatingly “artistic” sound of the Who and Led Zeppelin, Back in Black kicked ass. Listening to this album made you want to grab a stick and break something.

The opening riff of “Shoot to Thrill” can cause carpal tunnel syndrome trying to crank up the volume.

“Given the Dog a Bone” was a nightmare for English teachers and feminists, alike. Arguably, if the act was completed, then the verb tense of the title was proper.

Many complained that the title song was evil and anti-religious, that it was a poster child for reincarnation, that Brian Johnson was really Bon Scott, rising from the dead. Those people are now probably listening to Curt Cobain, and crying, while drinking cafe mocha.

Others com! plained that the music was just simple. So damn what. Ten songs, three chord guitar, screaming vocals. No “rock opera,” no social messages, just drink, smoke, and screw.

Isn’t that the way it’s supposed to be?

Was this review helpful to you?”

scooter

Wednesday, March 1st, 2006

rod
my housemate’s just bought a scooter - gets delivered in may

looks like it might be fun

isync my Nokia N70

Wednesday, March 1st, 2006

iSync with Nokia N70
I’ve just bought a Nokia N70 - well when i say bought i mean i got a bargain contract from e2save.com - check em out. The reason i got this phone is that i want to get more involved with mobile blogging, plus the camera is great.

My first problem was that Apple’s iSync doesn’t recognise the phone and of course Nokia ignores mac users. Theres loads of info on the web on how to get iSync working with the N70, just google “N70 iSync” but i’m fairly sure that Apple has done something in version 10.4.5 that stops this working so well (or it could be something to do with my setup).

Anyway - I gave £2.99 to the writer of The Dogs Blogs and she sent me the files i needed to get it syncing straight away. I’d actually been trying exactly the method she gave me, but it didn’t work. The solution is in the MetaClasses.plist file, which you’ll come across if you google for it, but only Andrea’s Dogs Blogs solution worked for me.

4 hours of frustration solved in 1 minute, well worth the price of a pint I think.