Dr. Andrew Besmer
0[]<?php
$animal[] = "aardvark";
$animal[] = "bat";
$animal[] = "cat";
$animal[1] = "bug";
$animal[4] = "elephant";
var_dump($animal);
/*
array(4) {
[0]=>
string(8) "aardvark"
[1]=>
string(3) "bug"
[2]=>
string(3) "cat"
[4]=>
string(8) "elephant"
}
*/
<?php
$name['first'] = 'Andrew';
$name['last'] = 'Besmer';
echo "Hey there " . $name['first'];
//Hey there Andrew
<?php
$name['first'] = 'Andrew';
$name['last'] = 'Besmer';
foreach($name as $key => $value)
{
//echo "Your " . $key . " name is " . $value . ".";
echo "Your $key name is $value.";
}
//Your first name is Andrew.Your last name is Besmer.
is_array($animals) - Is $animals an array true or falsecount($animals) - Return the number of elements in the arraysort($animals) - Sorts the array elementsexplode(',', 'Blue,Green') - Returns the array ['Blue','Green']unset($animals[0]) - Removes the element at index 0in_array(5, $values) - Is 5 in the array of $valuesisset($myArray['pos']) - Does an element at position pos exist in $myArray?strtoupper('Andrew') - Returns ANDREWstrtolower('Andrew') - Returns andrewsubstr($myString, 1, 5) - Return characters at posistions 1-5substr($myString, -4) - Return the last 4 characters of the stringstrpos('Andrew Besmer', 'Besmer') - Returns location Besmer is at in the string 7 or false if not found
?=&?first=Andrew&last=Besmer
form tag and require two attributes
action - Where the data will be sentmethod - How the data will be sent<form action="http://deltona.birdnest.org/~acc.besmera2/simulators/FormData/echo.php" method="GET">
</form>
<form action="http://deltona.birdnest.org/~acc.besmera2/simulators/FormData/echo.php" method="GET">
<label>First: <input type="text" name="first"></label><br>
<label>Last: <input type="text" name="last"></label><br>
<button type="submit">Submit</button>
</form>
<form action="http://deltona.birdnest.org/~acc.besmera2/simulators/FormData/echo.php" method="POST">
<label>First: <input type="text" name="first"></label><br>
<label>Last: <input type="text" name="last"></label><br>
<button type="submit">Submit</button>
</form>
$_GET and $_POST contain the name value pairs sent as part of a GET/POST request from your form1$_SERVER contains information relevant to the execution environment ['REQUEST_METHOD'] is of particular interest.<!DOCTYPE html>
<html>
<head>
<title>Hello There</title>
</head>
<body>
<?php
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
?>
<form method="POST" action="index.php">
<label>First Name: <input type="text" name="firstName"></input></label><br />
<label>Last Name: <input type="text" name="lastName"></input></label>
<input type="submit" value="Submit" name="submit">
</form>
<?php
}
else {
if(isset($_POST['firstName']) && isset($_POST['lastName']))
{
$firstName = "Somebody";
$lastName = "Cool";
if($_POST['firstName'] != '')
{
$firstName = $_POST['firstName'];
}
if($_POST['lastName'] != '')
{
$lastName = $_POST['lastName'];
}
echo "Hello there $firstName $lastName.";
}
else
{
echo "Sorry you must access this page by filling out the form.";
}
}
?>
</body>
</html>
XSS has been left in example for simplicity.↩