leapyear.php

This is a discussion on "leapyear.php" within the PHP Forum section. This forum, and the thread "leapyear.php are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 7th, 2007, 03:04
New Member
Join Date: Oct 2006
Location: Asheville NC
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
leapyear.php

tell me what wrong with this code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtmll/DTD/xhtmll-strict.dtd">
<html>
<head>
<title>Leap Year</title>
</head>
<body>
<?php
// Let's you know if a certain year is a leap year or not:
function is_leap_year($year) {
// If the year is divisible by 4 but not by 100 unless by 400
return ((($y % 4) == 0) && ((($y % 100) != 0) || (($y % 400) == 0)));
}
// Determine for a few years if they are leap years or not:
foreach ($_GET as $year) {
// Output the result:
echo "<p>{$year} = ", is_leap_year($year) ? 'Leap Year' : 'not', '</p>';
}
?>
</body
</html>
Reply With Quote

  #2 (permalink)  
Old Feb 9th, 2007, 17:03
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: leapyear.php

Can you post up the symptoms - tell us how it goes wrong. That way, we'll be able to find the problem more easily.
Reply With Quote
  #3 (permalink)  
Old Feb 11th, 2007, 01:45
Weird1993's Avatar
Moderator
Join Date: Feb 2007
Location: United States
Age: 15
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Weird1993 Send a message via Skype™ to Weird1993
Re: leapyear.php

Output from my run:
Quote:
{$year} = ", is_leap_year($year) ? 'Leap Year' : 'not', ''; } ?>
__________________
Daniel Thompson
danielwthompson.com

Last edited by Weird1993; Feb 11th, 2007 at 01:49.
Reply With Quote
  #4 (permalink)  
Old Feb 11th, 2007, 06:07
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: leapyear.php

Quote:
Originally Posted by Weird1993 View Post
Output from my run:
That appears to be the result of putting your PHP code into a page / URL that wasn't parsed by PHP - perhaps giving the file a ".html" extension rather than a ".php" one? The rest of the code is seen as junk by your browser, leaving just the code you quoted visible. If you do a "view source" you'll see the function and all the PHP.

I doubt whether that's the problem that dcarson was reporting - but it just may be. Actually, this is a very good example of the need to explain how something fails - if it fails in the way you report, it's a file naming issue but if (as I suspect) dcarson is seeing a different set of symptoms, my answer here won't help him.
Reply With Quote
Reply

Tags
code not working

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 21:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43