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..

Recommended Answers

All 3 Replies

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.

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).

thanks guys for ur reply and suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.