0

Hello..im a newbie in php, i'm curious about how to make a single file with multifunction, so i can call this file in another file. For example, i made a search function in "search.php". Then i want to call it in another file (more than one), to run a search function with different table in a single database or different filter. is it possible?, if yes how can i do it.

Thank for all..

3
Contributors
3
Replies
26
Views
2 Years
Discussion Span
Last Post by ma.da.7140
0

In each file that you want to call your search function in, you can use include('php_file_name') or require_once('php_file_name').
This will literally include that file inside the php markup for the calling file. You can call the search function as if it was part of the calling file's code.

0

Make a file that will contain all your functions, something like functions.php. You can put it in a special folder if you wish (like lib or something). The include this file whenever you need to call any of contained functions. You use either include or require construct for that. The difference between the two is minimal, basicaly only in how they react if the file can not be found. See the manual at the above links.

There are also cousins include_once and require_once that make sure that each file is included only once. Namely, it may happen that with many include/require calls you might try to include the same file more than once and if that file contains i.e. function definitions you would get an error (since the same function would be declared more than once).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.