Занятие по PHP
test.php
<?php
//$text = 1;
echo $text."<br />";
if($text == 1) {
echo "<u>Один</u>";
} else {
echo "Два";
}
for($i=1;$i<=5;$i=$i+0.5) {
echo $i."<br />";
}
$x = array();
for($i=1;$i<=5;$i++) {
$x[$i] = $i+1;
}
print_r($x);
echo "<br />";
$y = array();
$y["banan"] = "fruit";
$y["slon"] = "animal";
$y["kenguru"] = "animal";
print_r($y);
echo "<br />";
echo '<table border="1">';
foreach($y as $key => $val) {
echo "<tr><td>".$val."</td><td>".$key."</td></tr>";
}
echo "</table>";
?>
test2.php
<?php
$y = array();
$y["banan"] = "fruit";
$y["slon"] = "animal";
$y["kenguru"] = "animal";
echo "<b>".$y[$element].'</b>';
?>
test3.php
<?php
$y = array();
$y["banan"] = "fruit";
$y["slon"] = "animal";
$y["kenguru"] = "animal";
if($_REQUEST["formsend"] == "1") {
//echo "Форма отослана!";
if($y[$_REQUEST["element"]] != "") {
echo $_REQUEST["element"]." это ".$y[$_REQUEST["element"]];
} else {
echo $_REQUEST["element"]." нам неизвестно!";
}
} else {
echo $this->FormOpen();
echo '<input type="text" name="element" /><br />';
echo '<input type="hidden" name="formsend" value="1" />';
echo '<input type="submit" value="Отправить" />';
echo $this->FormClose();
}
?>
test4.php
<?php
function opred($slovo) {
$y = array();
$y["banan"] = "fruit";
$y["slon"] = "animal";
$y["kenguru"] = "animal";
if($y[$slovo] != "") {
echo $slovo." это ".$y[$slovo];
} else {
echo $slovo." нам неизвестно!";
}
echo "<br />";
}
if($_REQUEST["formsend"] == "1") {
//echo "Форма отослана!";
$elements = $_REQUEST["element"];
$elements = str_replace("\r", "", $elements);
$elements = str_replace("\n", " ", $elements);
$tarr = explode(" ", $elements);
//print_r($tarr);
foreach($tarr as $key1 => $slovo) {
opred($slovo);
echo "<br />";
}
/*
if($y[$_REQUEST["element"]] != "") {
echo $_REQUEST["element"]." это ".$y[$_REQUEST["element"]];
} else {
echo $_REQUEST["element"]." нам неизвестно!";
}
*/
} else {
echo $this->FormOpen();
echo '<textarea style="width: 100%;" rows="5" name="element"></textarea><br />';
echo '<input type="hidden" name="formsend" value="1" />';
echo '<input type="submit" value="Отправить" />';
echo $this->FormClose();
}
?>