tags:

views:

45

answers:

2

Hi all,

how do I call a defined function from a php script in another one?

I've got funktion.php which returns the time of the day.


<?php

  date_default_timezone_set("Europe/Berlin");

 function Uhrzeit()
 {
     echo date( 'H:i:s' );
}

 Uhrzeit();
?>

I'd like to call the function in another php script(test.php) so that Uhrzeit(); from test.php has access to the function Uhrzeit() from funktion.php.

How do I implement it?

Any help or hint or link is much appreciated. Thank you in advance.

+5  A: 
<?php
require_once("funktion.php");
Uhrzeit();
?>

(Edit: changed include to require_once, since it is more appropriate for this task.)

konforce
Now I see it. Thank you.
Faili
If it is working then accept the answer.
vinothkumar
Done. Could't do it b4 because of the time out ;-)
Faili
A: 

Another way of doing this is to use the return within the include, now this is not the best idea as its a waste of a file but non the less knowledge is knowledge:

functions.php

<?php
    return date( 'H:i:s' );
?>

and use like

echo include 'functions.php';
RobertPitt
Knowledege is knowledge and I'm thankful for every piece of it. Ty
Faili