esercizi in php

This commit is contained in:
2014-10-25 15:24:01 +02:00
parent 8e3c635fd9
commit c318b09580
10 changed files with 448 additions and 0 deletions

5
footer.html Normal file
View File

@@ -0,0 +1,5 @@
</body>
</html>

17
header.html Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Esercizi</title>
<meta name="author" content="xgiovio"/>
<meta name="description" content="A simple test page"/>
<meta name="keywords" content="Ormai google non se le fila piu"/>
<meta name ="robots" content="index"/>
<meta charset="utf-8"/>
</head>
<body>

62
php4.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
$a = array('a','b','c');
print_r($a);
$b = array ('alfa'=> 0, 'beta'=> 1,'gamma' =>3);
print_r($b);
foreach ($a as $key => $value) {
echo $key . $value;
}
foreach ($b as $key => $value) {
echo $key . $value;
}
reset($a);
list($key,$value) = each($a);
echo $key , $value;
list($key,$value) = each($a);
echo $key , $value;
echo"<br>";
reset($b);
list($key,$value) = each($b);
echo $key , $value;
list($key,$value) = each($b);
echo $key , $value;
$c = explode(" ","mario marra bello");
print_r($c);
$d="marco";
$e="aflio";
$f="fonzo";
$k= compact('d','e','f');
print_r($k);
$j= extract($k,EXTR_PREFIX_ALL,"XG");
echo $XG_d;
$x= str_split("mario");
unset($x);
foreach( count_chars("mario",1) as $key => $desc ){
$x[chr($key)] = $desc;
}
print_r($x);
?>

15
php_1.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
$value = 0;
for ($i=0;$i<10;$i++){
$value+=5;
echo "$value ";
}
?>

50
php_1_2.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
include ('header.html');
echo<<<_css
<style>
table,td {
border:1px solid black;
}
</style>
_css;
$counter_x;
$counter_y;
echo "<table>";
for ($counter_x = 1 ;$counter_x <= 10; $counter_x++)
{
echo '<tr>';
for ($counter_y = 1 ;$counter_y <= 10; $counter_y++)
{
echo '<td>';
echo $counter_x * $counter_y;
echo '</td>';
}
echo '</tr>';
}
echo "</table>";
include ('footer.html');
?>

48
php_1_3.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
include ('header.html');
///////////////////////////
echo<<<_css
<style>
</style>
_css;
echo "\n";
///////////////////////////
for ($i=1;$i<=9;$i++){
echo "<p>\n";
echo "$i : " . fattoriale($i);
echo "</p>\n";
}
include ('footer.html');
function fattoriale ($input){
if ($input == 1){
return 1;
} else {
return (fattoriale($input -1 ) * $input);
}
}
?>

53
php_1_4.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
include ('header.html');
///////////////////////////
echo<<<_css
<style>
</style>
_css;
echo "\n";
///////////////////////////
echo "<table>";
$value = 0;
for ($i=1;$i<=5;$i++){
echo "<tr>";
for ($y=1;$y<=4;$y++){
echo "<td>";
echo ++$value;
echo"</td>";
}
echo "</tr>";
}
echo "</table>";
include ('footer.html');
?>

76
php_1_5.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
include ('header.html');
///////////////////////////
echo<<<_css
<style>
table {border: 1px solid black;}
td {
border: 1px solid black;
text-align:center;
}
table tr:nth-child(3n+2) {
background-color:green;
}
table tr:nth-child(3n+3) {
background-color:pink;
}
table tr:nth-child(3n+4) {
background-color:red;
}
tr#first {
background-color:yellow;
}
</style>
_css;
echo "\n";
///////////////////////////
echo "<table>";
echo "<tr id=\"first\"> <td>Numero</td> <td>Riga</td> </tr>";
for ($i=1;$i<=12;$i++){
echo "<tr>";
for ($y=1;$y<=2;$y++){
echo "<td>";
if ($y == 1){
echo $i;
} else {
echo "riga " . $i;
}
echo"</td>";
}
echo "</tr>\n";
}
echo "</table>";
include ('footer.html');
?>

82
php_2.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
include ('header.html');
///////////////////////////
echo<<<_css
<style>
</style>
_css;
echo "\n";
///////////////////////////
$stringa = "alfio";
echo "$stringa\n";
echo "<br>";
$vocali = 0;
$consonanti = 0;
$acharacter=0;
$numeri = 0;
for ($i=0;$i< strlen($stringa);$i++){
$character = substr("$stringa", $i, 1);
switch ($character) {
case "a":
$vocali++;
$acharacter++;
break;
case "e":
$vocali++;
break;
case "i":
$vocali++;
break;
case "o":
$vocali++;
break;
case "u":
$vocali++;
break;
default :
if (is_numeric($character)){
$numeri++;
} else{
$consonanti++;
}
}
}
echo "vocali: $vocali\n";
echo "<br>";
echo "consonanti: $consonanti\n";
echo "<br>";
echo "a character: $acharacter\n";
echo "<br>";
echo "numeri: $numeri\n";
echo "<br>";
foreach( count_chars($stringa,1) as $key => $desc ){
echo chr($key) . " ripetuta " . $desc . "volte/n";
echo"<br>";
}
include ('footer.html');
?>

40
php_3.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
include ('header.html');
///////////////////////////
echo<<<_css
<style>
</style>
_css;
echo "\n";
///////////////////////////
if ($_GET == null){
} else {
echo "cioa";
}
include ('footer.html');
?>