Current location: Hot Scripts Forums » Programming Languages » PHP » User Functions


User Functions

Reply
  #1 (permalink)  
Old 06-15-03, 03:20 AM
DA Master DA Master is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Yorkshire
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
User Functions

When creating a function that will show the date I use the following function...

PHP Code:

<?php

function ShowDate()
{
    
date("F j, Y");
}
?>
Then I call the file that this is in via the require_once() function then...

PHP Code:

<?php ShowDate(); ?>

Yet when testing nothing shows in the page. What's wrong?
Reply With Quote
  #2 (permalink)  
Old 06-15-03, 03:49 AM
daynah's Avatar
daynah daynah is offline
Newbie Coder
 
Join Date: Jun 2003
Location: CA, USA
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Cool

I think these changes will help.

Function:
PHP Code:

<?php

function ShowDate()
{
    return 
date("F j, Y");
}
?>
To display,
PHP Code:

<?= 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 Code:

<?php

function ShowDate()
{
    echo 
date("F j, Y");
}
?>
To display,
PHP Code:

<?php ShowDate(); ?>

Both way works. You just need a way to echo the data somewhere.
__________________
PHP Princess.net | Daynah.net
Reply With Quote
  #3 (permalink)  
Old 06-15-03, 03:49 AM
Steven Steven is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Singapore
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Add an echo infront of the date()

<?php

function showdate()
{
echo date("F j, Y");
}

?>
Reply With Quote
  #4 (permalink)  
Old 06-15-03, 03:52 AM
Steven Steven is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Singapore
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
oops.. looks like daynah replied while i am replying too..
Reply With Quote
  #5 (permalink)  
Old 06-15-03, 05:00 AM
DA Master DA Master is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Yorkshire
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks daynah. All sorted now.
__________________
PHP Code:

<?php if(PHP_OS == 'Windows') { echo "Doh"; } ?>

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
user management and searching.. alvibd Script Requests 1 09-27-03 12:53 PM
Ad management and optimisation using php surebetdmg PHP 0 08-28-03 06:45 PM
Array passing between functions alfreds PHP 1 08-25-03 05:29 AM
Modify user settings... amailer Hot Scripts Forum Questions, Suggestions and Feedback 1 07-14-03 08:49 AM
send mail to user onlynils New Members & Introductions 1 07-04-03 01:18 PM


All times are GMT -5. The time now is 05:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.