View Full Version : User Functions
DA Master
06-15-03, 04:20 AM
When creating a function that will show the date I use the following function...
<?php
function ShowDate()
{
date("F j, Y");
}
?>
Then I call the file that this is in via the require_once() function then...
<?php ShowDate(); ?>
Yet when testing nothing shows in the page. What's wrong?
I think these changes will help. :)
Function:
<?php
function ShowDate()
{
return date("F j, Y");
}
?>
To display,
<?= ShowDate(); ?>
The reason I used return in the function is because date returns a string, so you want you function to do the same.
The display part, I used <?= ShowDate(); ?> instead of <?php ShowDate(); ?> because the <?= means to display the result (echo).
You can also have it like this:
Function:
<?php
function ShowDate()
{
echo date("F j, Y");
}
?>
To display,
<?php ShowDate(); ?>
Both way works. :) You just need a way to echo the data somewhere.
Add an echo infront of the date()
<?php
function showdate()
{
echo date("F j, Y");
}
?>
oops.. looks like daynah replied while i am replying too.. :P
DA Master
06-15-03, 06:00 AM
Thanks daynah. All sorted now.
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.