Docsity

Progettazione Web PHP (Inglese), Dispense di Elementi di Informatica

Anteprima parziale del testo

Scarica Progettazione Web PHP (Inglese) e più Dispense in PDF di Elementi di Informatica solo su Docsity!

Progettazione Web

PHP

Francesco Marcelloni

Dipartimento di Ingegneria dell’Informazione

Università di Pisa

ITALY

What is PHP

 PHP is recursive acronym for PHP: Hypertext

Preprocessor

 PHP is a server-side scripting language

 PHP scripts are executed on the server

 PHP supports many databases (MySQL,

Informix, Oracle, Sybase, Solid, PostgreSQL,

Generic ODBC, etc.)

 PHP is an open source software

 PHP is free to download and use

Why PHP?

 PHP runs on different platforms (Windows, Linux,

Unix, etc.)

 PHP is compatible with almost all web servers used

today (Apache, IIS, etc.)

 PHP is FREE to download from the official PHP

resource: www.php.net

 PHP is easy to learn and runs efficiently on the server

side

Where to Start?

 To get access to a web server with PHP support, you

can:

 Install Apache (or IIS) on your own server, install PHP, and MySQL  Or find a web hosting plan with PHP and MySQL support

PHP Syntax

 A PHP scripting block can be placed anywhere in the

document.

 A PHP file normally contains HTML tags, just like an HTML file,

and some PHP scripting code

This is true.

This is false.

 When PHP hits the ?> closing tags, it simply starts outputting

whatever it finds (except for an immediately following

newline) until it hits another opening tag.

PHP Example

PHP Example

 NOTE: The file must have a .php extension. If the file has a .html extension, the PHP code will not be executed.

PHP Variables

 All variables in PHP start with a $ sign symbol.

$var_name = value;

 In PHP, a variable does not need to be declared before

adding a value to it.

 PHP automatically converts the variable to the correct

data type, depending on its value.

 A variable name is case-sensitive and must start with

a letter or an underscore "_"

 A variable name can only contain alpha-numeric

characters and underscores (a-z, A-Z, 0-9, and _ )

PHP Types

PHP supports eight primitive types.

 Four scalar types:

 boolean  integer  float (floating-point number)  string

 Two special types:

 NULL

 resource

 Two compound types:

 array  object

PHP Types

Floating-Point Numbers

 Floating point numbers

 The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE format).

PHP Types

NULL and Resource

 NULL

The special NULL value represents a variable with no value. NULL is the only possible value of type NULL. A variable is considered to be null if:  the constant NULL has been assigned to it  it has not been set to any value yet.  it has been unset(). The function is_null() allows evaluating whether the value of a variable is NULL

 Resource

 A resource is a special variable, holding a reference to an external resource. Resources are created and used by special functions. For instance, dbase_open() opens a database.

PHP Types

String

 Complex Curly Syntax Any scalar variable, array variable or object property with a string representation can be included via this syntax.  Simply write the expression the same way as it would appear outside the string, and then wrap it in { and }.  Since { can not be escaped, this syntax will only be recognized when the $ immediately follows the {.  Use {$ to get a literal {$.  PHP uses the same escape sequences (“\”) as in C++

\n, \t, \, $, \”, \0, [0-7]{1,3}, \x[0-9A-Fa-f]{1,2}

PHP Types

String

 Complex Curly Syntax (example) width}00 centimeters broad."; // Works echo "This works: {$arr[4][3]}"; ?>

PHP Types

String

 Characters within strings may be accessed and modified using square array brackets (or also braces)

PHP Types

String

 Concatenation operator ('.') - returns the

concatenation of its right and left arguments.

 Concatenating assignment operator ('.=') -

appends the argument on the right side to the

argument on the left side.