<?php
$student["name"] = "Ann";
$student["surname"] = "Petrova";
$student["age"] = 20;
print count($student);
?>
$student, count(). $student, . 3.
foreach
. foreach.
5.7 foreach
<?php
$students = array("Ira","Vadim","Alex","Ann);
foreach($students as $temp)
{
print "$temp<br>";
}
?>
$students, . foreach. $students , , $temp , . foreach : $temp, print, ( ) foreach. , . :
Ira
Vadim
Alex
An4n
, , foreach -. , , .
5.8
<?php
$tel = array(
"Max Koshelev" => "580-46-82",
"Ann Reish"=> "589-90-34",
"Pashsa Golikov" => "480-57-58"
);
foreach ($tel as $key=>$temp);
{
print "$key - $temp<br>";
}
?>
$tel , $key (), , $temp , .
:
Max Koshelev - 580-46-82
Ann Reish - 589-90-34
Pashsa Golikov - 480-57-58
sort()
(.. , , ) .
sort() , , , , - . .
|
|
5.9 sort()
<?php
$abc = array("c", "a", "b");
sort($abc);
foreach($abc as $temp)
{
print "$temp<br>";
}
?>
$abc.
A
B
C
sort() . c, sort() a. rsort().
, asort() ( ) ksort() ( ). arsort() krsort() .
, , , . .
, .
.6.
, . . Web- Web- HTML-. PHP .
PHP , . - $_POST $_GET. ( method form). , . , GET name , action form . :
echo $_GET['name'];
POST:
echo $_ POST['name'];
POST GET? .
,
, HTML- PHP-.
6.1 HTML- ( primer6_1.html)
<html>
<head>
<title> Form </title>
</head>
<body>
<form action="primer6_2.php" method="GET">
: <input Type="password" Name = "pas" Size="10" Maxlength = "10">
<input Type="Submit" Value=" " Name = "go" >
</form>
</body>
</html>
, ( password ) pas Submit. .
|
|
<form>. , : <>. HTML : <> </>. <> , </> .
<form> . , , , , , ACTION METHOD. ACTION primer6_1.php, . , , , HTML. METHOD , . POST URL , GET URL . , , .
<Input> . Type , Name , Size , Maxlength , .
Submit , , . VALUE, .
, .
6.1 HTML-
PHP-. , .
6.2 HTML- ( primer6_2.php )
<?php
if ($_GET['pas'] == "17er0482")
{
print " !";
}
else
{
print " !";
}
?>
, primer6_2.php, , . $_GET['pas'], . , . PHP- (17er0482) .
. , , , . select.
6.3 HTML- select (primer6_3.html)
<html>
<head>
<title>Form with select </title>
</head>
<body>
<form action="primer6_4.php" method="GET">
: <input type="text" name="nick" size = "8" maxlength = "8">
<br>
:
<br>
<textarea name="info" rows = "5" cols = "30">
</textarea>
<br>
:
<br>
<select name = "interests[]" multiple>
<option>
<option>
<option>
|
|
<option>
</select>
<br>
<input type="submit" value=" " Name = "go">
</form>
</body>
</html>
, , , "interests[]", $_GET['interests']. primer6_3.php. 6.2 , .
6.2 -
6.4 ( primer6_4.php)
<?php
print "<h1>".$_GET['nick']."</h1><br>";
print "<b> <br>";
print $_GET['info']."<br>";
print " </b><br>";
foreach($_GET['interests'] as $temp)
{
print "<i>".$temp."</i><br>";
}
?>
PHP- , ($_GET['nick'], $_GET[$info] $_GET[$interests).
HTML- PHP-
PHP-, , , , . , , PHP HTML.
PHP , , HTML-. HTML- Web-, PHP , PHP. HTML- , PHP HTML-, . , Web- : , ( Web- ), , , , .
HTML , Web- HTML , , . PHP .
, . -, .
6.5 ( primer6_6.php)
<?php
$real_word = "bike";
if ($_GET['word'] = = "")
{
print " ";
}
elseif ($_GET['word'] = = $real_word)
{
print " ";
}
else
{
print " ";
}
?>
<html>
<head>
<title> </title>
</head>
<body>
<form method = "GET">
, : <input type="text" name="word">
<input type="submit" value=" " name="go">
</form>
</body>
</html>
PHP , $real_word , . $word, , . , , , , , , . HTML- . , , , .
|
|
, ACTION FORM. , .
, , Web-, , .
: , , . - , , . , .
, , , . header();
Location, .
6.5.
6.6 Location
<?php
$real_word = "bike";
if ($_GET['word'] = = "")
{
print " ";
}
elseif ($_GET['word']= = $real_word)
{
header("Location: winner.html");
}
else
{
print " ";
}
?>
<html>
<head>
<title> </title>
</head>
<body>
<form method = "GET">
, : <input type="text" name="word">
</form>
</body>
</html>
, , , winner.html ( , ). (Location:) , , , HTML.
-, , , , .
.7.
; . . . , , - . , , (. 7.8).
, PHP- include(). PHP- , . , .
include() , .
7.1 ( primer7_1.php)
<html>
<head>
<title> </title>
</head>
<body>
<?php
include("primer7_2.php");
?>
</body>
</html>