Cheatsheet für PHP

  • Interpolation in PHP
    $s="Datei {$this->name_config_ini()} loeschen";
  • Gleichheit in PHP
    if ($string == "xxx") echo "ok";
    $a != $b // oder: $a <> $b
  • Schleifen in PHP
    break
    continue
  • Strings in PHP
    $a = "Das sind $anzahl Autos.\n";
    $b = 'vier'; // keine Interpolation
    $satz = $wort1 . $wort2;
  • Funktionen in PHP
    function($x, $y) {
       return $z;
    }
  • Regular Expressions in PHP
    $text = "Das ist ein Test.";
    preg_match("/.*(ist).*(Te)/", $text, $matches);

    echo $matches[0] . "\n"; // 'Das ist ein Te'
    echo $matches[1] . "\n"; // 'ist'
    echo $matches[2] . "\n"; // 'Te'
  • Klassen in PHP
    class Meine_Klasse {
       public $xy;
       private $ab; // $this->ab;
       const CONST_VALUE = 'Ein konstanter Wert'; // self::CONST_VALUE

       private function meine_funktion($par) {
          $this->ab = 5;
          echo "Ergebnis = {$this->weitere_funktion()}\n";
          return $par + 3;
       }
       private function weitere_funktion() {
       }
    }
  • Zeichen ersetzen in PHP

Siehe auch

Klassifikation