Cours SGBD Aide-mémoire PHP
15 novembre 2006
1 PHP
<?php . . . ?>
1.1 Commentaires
// Commentaire (une seule ligne) # Commentaire (une seule ligne) /* Commentaire */ (plusieurs lignes)
1.2 Écriture de la page en cours
echo 'Hello world!';
1.3 Littéraux
Nombres : 42, 1.2
Chaînes : 'Hello', "Hello"
Caractères spéciaux : \n, \t, \\, \$, \', \"
Tableaux indicés : array('a',3,"Hello") Tableaux associatifs : array('a'=>24,'b'=>42)
1.4 Opérateurs
Aectation : $A=42;
Concaténation : 'Titi ' . " et " . ' Gros-minet', "$A + $B" (mais pas '$A + $B') Opérations arithmétiques : $a+$b, $a-$b, $a*$b, $a/$b, $a%$b
Comparaisons : $a==$b, $a!=$b, $a<$b, $a>$b, $a<=$b, $a>=$b, $a===$b, $a!==$b Opérateurs logiques : $a && $b, $a || $b, !$a
1.5 Structures de contrôle
if (condition) { instructions; } else { instructions; } while (condition) { instructions; }
for (initialisation;condition;pas) { instructions; } foreach ($tableau as $valeur) { instructions; } foreach ($assoc as $cle => $valeur) { instructions; } break;
continue;
1.6 Fonctions
function ma_fonction($arg1,&$arg2) { ...return $c;
list ($a,$b,$c)=fonction();}
1
1.7 HTTP
$_REQUEST('toto')
header("Location: nouvelle_page.php")
1.8 Fonctions prédénies
1.8.1 Numériques abs($f)
ceil($f) empty($f) floor($f) round($f)
max($f1,...,$fk) min($f1,...,$fk) rand()
1.8.2 Chaînes de caractères explode($sous_chaine,$chaine) implode($chaine,$tableau)
strstr($chaine,$sous_chaine,$decalage) strlen($chaine)
strpos($chaine,$sous_chaine,$decalage) substr($chaine,$debut,$longueur) 1.8.3 Dates
date("d/m/Y") 1.8.4 Tableaux indicés
is_array($tab) count($tab) sort($tab) rsort($tab) max($tab) min($tab)
1.8.5 Tableaux associatifs key($assoc)
current($assoc) next($assoc) prev($assoc) next($assoc) ksort($tab) krsort($tab)
2