Forum Moderators: coopster
<?php
function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array())
{
$time = time();
echo generate_calendar(date('Y', $time), date('n', $time));}
?>
I am calling a function from within a function so it is printing a blank page :( where do I need to place this code in order for it to work?....
echo generate_calendar(date('Y', $time), date('n', $time));}
If you add:
error_reporting(E_ALL);
First problem here is probably
$pn = array(). This occurs in a default variable value inside the declaration of a function. Strictly speaking, this is a no-no - default variable values in function declarations are only supposed to be static integers, floats, and strings - no variables, functions, or fancy stuff allowed here. If PHP isn't generating an error here, it may well in a future of PHP, since this is not allowed by the manual, and PHP is a language that tries to stick to the manual.
Second problem - very big problem - you call this function within itself (the very same function), without having any in-built limits. So this is an infinitely recursing function - a function which will just keep calling itself, and keep calling itself, and keep calling itself. If you have an older version of PHP, this might even cause your server to crash.
Recursive functions are touchy beasts and you really should try your best to avoid writing recursive functions until you are very comfortable indeed with PHP and have an excellent intuitive grasp of how things in it work. You know you're on this level when this forum's mods address you as "d00d" and formulate replies to you in leet script.
See instead if you can't re-write this function to just loop through an array. If you can't avoid a function that uses recursion, make sure it has a level variable in the function arguments that is augmented +1 every time the function is executed, and before the function calls itself again, checks this variable to make sure it isn't above a certain level max (and make that level max a pretty low number, too).
I found some calendar code here...
As long as you are looking for calendar code, you might want to look at some calendar classes. I looked into what it might take to write my own calendar and decided, in this case, there was no reason to re-invent the wheel. The class objects already exist in the public domain. If you need help locating a calendar class sticky me for the url... not too sure about dropping it here.