Académique Documents
Professionnel Documents
Culture Documents
•Server-Side Scripting
•MySQL
•PHP
•Apache
•Variables
•Control Structure
•Looping
Server-Side Scripting
Server-side
Dynamic content.
Computational capability.
Database and file system access.
Network access (from the server only).
Built-in libraries and functions.
Known platform for execution (as opposed to client-
side, where the platform is uncontrolled.)
Security improvements
Introduction to PHP
and MySQL
• OR
Free Download
PHP: http://www.php.net/downloads.php
• Comments:
– #
– //
– /* . . . */
Basic PHP Syntax
<?php
The scope of a variable function mul()
{
defined within a function global $start;
is local to that function. print "<tr>";
for ($num=1; $num <= 10; $num++ )
{
$cell = $num * $start;
A variable defined in the print "<td> " . $cell . " </td>";
}
main body of code has a print "</tr>";
global scope. }
$start = 0;
print "<table border=1
cellpadding=3>";
If a function needs to use a while ( $start <=10 )
{
variable that is defined in the mul();
main body of the program, it $start++;
}
must reference it using the print "</table>";
"global" keyword, like this: ?>
Strings in PHP
• a string is a sequence of letters, symbols, characters and arithmetic values or combination
of all tied together in single or double quotes.
• String literals are enclosed in single or double quotes
• Example:
<?php
$sum = 20;
echo 'the sum is: $sum';
echo "<br />";
echo "the sum is: $sum";
echo "<br />";
echo '<input type="text" name="first_name" id="first_name">';
?>
– Double quoted strings have escape sequences (such as /n or /r) interpreted and
variables interpolated (substituted)
– Single quoted strings have neither escape sequence interpretation nor variable
interpolation
– A literal $ sign in a double quoted string must be escaped with a backslash, \
– Double-quoted strings can cover multiple lines
Escaping quotes with in quotes
Example 1:
<?php
$str = "\"This is a PHP string examples quotes\"";
echo $str;
?>
Example 2
<?php
$str = 'It\'s a nice day today.';
echo $str;
?>
The Concatenation Operator