View Full Version : Php function call from another file


Rodie
09-29-2005, 05:34 PM
Hi

I have two PHP pages (two file .php).
The first file is the starting file.
I would like the 2nd file to have only a list of functions that can possibly return something or do echo on the main page.

So how can I call the functions of the 2nd file from the 1st file ?
I know that an include '2ndpage.php' can refer to the 2nd file, but to refer to a function of the 2nd file... Didn't find that...

Thanks a lot :)

putnamehere
09-29-2005, 05:42 PM
Woudlent you jsut link to the page,
try this but i aitn sure, the code is only ther to so how it would be used with teh if and else command.
<?php
$hello = "hello"
$next = "action.php"
if ($hello==hi)
Echo ('wahtver this is jsut a eg of some random code')
else $next

Douglas
09-29-2005, 05:49 PM
Woudlent you jsut link to the page,
try this but i aitn sure, the code is only ther to so how it would be used with teh if and else command.
<?php
$hello = "hello"
$next = "action.php"
if ($hello==hi)
Echo ('wahtver this is jsut a eg of some random code')
else $next
that makes no sense at all lol sorry,
but as for the original question,
you have some funnctions in the 2ndpage.php right?
and you want them executed in the 1stpage.php right?
then just include them:

<?
include("2ndpage.php");
?>

since your host supports php that will execute 2ndpage.php in 1stpage.php, you can even combine variables:

<?
// 2ndpage.php
$variable="What";
echo $variable;
?>


<?
// 1stpage.php
include("2ndpage.php");
echo $variable;
?>


that will echo What twice :)

putnamehere
09-29-2005, 05:56 PM
I know that an include '2ndpage.php' can refer to the 2nd file, but to refer to a function of the 2nd file... Didn't find that...

So how can I call the functions of the 2nd file from the 1st file ?

it makes more sence than yours. This person knows about inclueds.

Rodie
09-29-2005, 06:00 PM
Indeed, it work perfectly. I can call variables, functions... whatever.
PS: Faut encore moins manger la neige marron :lolol::lolol::lolol:

Thanks a lot guys.

Douglas
09-29-2005, 06:06 PM
no prob :D

putnamehere
09-29-2005, 06:10 PM
Thanks a lot guys.
ok no prob =)