Author: techfox9
php introduction notes – part 2..
Wednesday, July 2nd, 2008 @ 12:09 am
From
https://www6.software.ibm.com/developerworks/education/os-phptut1/section4.html
Functions
Creating a function
<?php
function checkPasswords($firstPass, $secondPass){
if ($firstPass == $secondPass) {
echo “<p>Passwords match. Thank you.</p>”;
} else {
echo “<p>Passwords don’t match. \
Please try again.</p>”;
}
}
?>
Returning a value
<?php
function validate($allSubmitted){
$message = “”;
…
if ($message == “”){
$message = “OK”;
}
return $message;
}
…
if (validate($_POST) == “OK”) {
echo “Thank you for registering!”;
} else {
echo “There was a problem with your registration..”;
}
?>
Including files
<?php
include(“top.txt”);
?>
…
<?php
include(“bottom.txt”);
?>
Requiring files
<?php
include(“top.txt”);
require(“scripts.txt”);
?>
Avoiding duplicates (includes)
<?php
include_once(“top.txt”);
require_once(“scripts.txt”);
?>