PHP: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiunto paragrafo "carratteristiche"
Nessun oggetto della modifica
Riga 18:
 
Fornisce un'API specifica per interagire con [[Apache]], nonostante funzioni naturalmente con qualsiasi server. E' anche ottimamente integrato con [[MySQL]], per il quale possiede ben due API. Per questo motivo esiste un'enorme quantità di script e librerie in PHP, disponibili liberamente su Internet, che interagiscono con MySQL.
 
== Esempio di codice ==
 
Il seguente esempio stampa il testo della canzone ''99 Bottles of Beer''.
 
<pre>
<nowiki>
<?php
/*
* Questo è un commento. Altri modi per commentare sono i simboli // e #
* Questo tipo di commenti non ha bisogno degli asterischi (*) all'inizio
* di ogni riga, ma lo si fa per convenzione. I simboli // e #
* commentano solo il testo che si trova dopo di essi e fino alla fine della riga;
* non c'è bisogno di finire il commento con qualche carattere speciale.
*/
 
/*
* Prima definiamo una funzione chiamata "plural".
* Restituisce una "s" se l'argomento passato non è 1.
*/
function plural($number) {
return ($number != 1 ? "s" : "");
// The ternary operation above is a conditional structure similar to if-else: (condition ? true : false)
}
 
// We define a variable called $l to contain an HTML line break
// as well as a carriage return and line feed:
$l = "<br />\r\n";
 
for ($i = 99; $i > 0; $i--) {
print "$i bottle" . plural($i) . " of beer on the wall,$l";
// We don't actually need a new print for each line. Let's see:
print "$i bottle" . plural($i) . " of beer.$l
Take one down, pass it around,$l" .
($i - 1 != 0 ? $i - 1 : "no more") .
" bottle" . plural($i - 1) . " of beer on the wall.$l$l";
 
/*
* PHP allows you to put strings on multiple lines, as long as
* it eventually finds a semicolon (;) to terminate it.
* A period (.) joins (concatenates) strings together.
* Variables, the $-symbol things, are parsed (interpolated)
* inside double quotation marks ("), but wouldn't be parsed
* inside single quotation marks ('). Functions, such as
* plural(), are not parsed inside any quotation marks.
*/
}
 
print "Go to the store,$l buy some more,$l 99 bottles of beer on the wall!";
 
?>
</nowiki>
</pre>
 
== Collegamenti esterni ==