> From: "Stephen" <[EMAIL PROTECTED]> > Cc: "PHP List" <[EMAIL PROTECTED]> > Sent: Wednesday, November 20, 2002 8:52 PM > Subject: Re: [PHP] Reading part of a file
> What I'm doing is having a PHP part, let's say that it's a calculator that > adds module, that does the adding. The second part of the file is the form > that the user uses to put in the numbers. That's what I want to do... If you have a piece of php code sitting in a file, you can use it anytime by including or requiring it. Say you have a file named add.php and in it you have: --- Top of file --- <?php function add($addend1, $addend2) { return ($addend1 + $addend2); } ?> --- End of file --- in another file named page calc.php you can do a: --- Top of file --- <?php require 'add.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $sum = add($_POST['addend1'],$_POST['addend2']); echo "<br>The sum of {$_POST['addend1']} and {$_POST['addend2']} is $sum<br>\n"; } ?> <form method="post" action="calc.php"> <input type="text" name="addend1" size="10"><br> <input type="text" name="addend2" size="10"><br> <input type="submit" name="submit" value="Add them"> </form> --- End of file --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php