开发者

How do I call a defined function in another php script?

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 m开发者_StackOverflow中文版uch appreciated. Thank you in advance.


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

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜