1

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.

2 Answers 2

7
<?php
require_once("funktion.php");
Uhrzeit();
?>

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

Sign up to request clarification or add additional context in comments.

1 Comment

Done. Could't do it b4 because of the time out ;-)
1

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';

1 Comment

Knowledege is knowledge and I'm thankful for every piece of it. Ty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.