Re: Reading part of a file

From: Date: Thu, 21 Nov 2002 02:27:58 +0000
Subject: Re: Reading part of a file
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-125367@lists.php.net to get a copy of this message
> From: "Stephen" <webmaster@melchior.us> > Cc: "PHP List" <php-general@lists.php.net> > 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 ---

« previous php.general (#125367) next »