Jump to main content
URZ Workshop „Creating websites with TUCAL“
PHP

PHP

Syntax

  • PHP is a scripting language mainly used for creating dynamic web pages or web applications
  • PHP code is processed on the server side and the output of the web server's PHP interpreter is sent to the web browser (usually as an HTML document, other file types such as images or PDF files are also possible)
  • PHP tags <?php and ?> are used to indicate to the PHP interpreter that PHP commands should be recognized and executed
  • PHP offers broad database support, i. e. querying and sending data to a database
  • There are numerous programming possibilities with PHP, so use the following descriptions:

PHP source code examples

<?php
// Text outputs are generated with echo
// Always pay attention to the quotation marks and the semicolon at the end of a statement!
echo 'Hello World!';

// Inclusion of another file
require_once('inc/functions.inc');

/**
 * A longer comment for a PHP function
 * Arguments can be passed to the function when it is called, e. g.
 * to change the output
 */
function exampleFunction($parameter false) {
    $output '';
    if ($parameter == true) {
        // output current date
        $day date('z') + 1;
        $output date('d. m. Y') . ', day ' $day ' of the year. ';
    } else {
        // output something else
        $output 'Here is something else than the date of today.';
    }
    return $output;
}

// Here the function is called
echo exampleFunction(true); // displays the current date

// This is what a simple array looks like
$formen = array('circle''square''triangle');
echo $formen[1]; // generates "square" as output

// This is what a more complex array looks like (associative)
// => these arrays are often needed for the TUCAL extension modules
$drink = array(
    'content' => 'coffee',
    'additive' => 'milk foam',
    'sugar' => false,
    'size' => array('large''medium''small'),
    'quantity' => 2,
);
echo $drink['content'] . ' (' $drink['size'][0] . ')'// create "coffee (large)" as output
?>

Implementation in TUCAL