Pagine

martedì 13 settembre 2011

USO DELLE STRINGHE

stringa_1.php

<html>
<head>
<title>Gestione di una stringa di caratteri</title>
</head>
<body bgcolor="f0fff0">
<center>
<font face="Arial">
<h2>Digitare una stringa di caratteri</h2>
<form action="stringa_2.php" method="POST">
<input name="frase" size="100" maxlength="100"><p>
<input type="submit" value="Invia">
<input type="reset" value="Cancella tutto">
</font>
</center>
</form>
</body<
</html>
stringa_2.php

<html>
<head>
<title>Gestione di una stringa di caratteri</title>
</head>
<body bgcolor="f0fff0">
<font face="Arial">
<?php
//Inizializzazione delle variabili
$frase=$_POST['frase'];
//Visualizzazione di $frase
echo $frase . "<hr>";
//Visualizzazione della frase con il for
for($i=0; $i<strlen($frase);$i++) {
echo chr(ord(substr($frase,$i,1))+2);
}
echo "<hr>";


//Utilizzo di substr
echo substr ($frase,5,10);
echo "<hr>";

//Utilizzo di strtoupper
echo strtoupper ($frase);
echo "<hr>";

//Utilizzo di strtolower
echo strtolower ($frase);
echo "<hr>";

?>
</font>
</body>
</html>