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.
|
|
|
|
|
![]() |
||
leapyear.php
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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> |
|
|
|
|||
|
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.
|
|
||||
|
Re: leapyear.php
Output from my run:
Quote:
Last edited by Weird1993; Feb 11th, 2007 at 01:49. |
|
|||
|
Re: leapyear.php
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. |
![]() |
| Tags |
| code not working |
| Thread Tools | |
|
|