In PHP we can enter comments in our code (which is strongly advised to read your code elsewhere), by following ways:
/ / Everything that follows these two slashes is the comment will not be interpreted by the server
/ * All that is between these characters is the comment will not be interpreted by the server * /
It may also introduce php code in HTML, and yes! On the previous script hello world, so I could add a title to my page (for example) by writing:
Code:
<html>
<head>
<title> my page title </ title>
</ head>
<body>
<? Php
echo "hello world";
>
</ body>
</ html>
In this case php include in html, the file is named with an extension. Php forever.
variables
Php variables, as in any programming language, are objects that can contain data. These data can be changed at will during the execution of a script. They are essential for programming!
Php variables can be named with letters, numbers, and the _, but the name can not start with a digit. These names are sensitive and they always (well in php) $ dollar sign in front. Example: $ nom_variable variable is a valid, but $ 89variable is not valid name.
PHP has another advantage with variables: there is no need to define or to typer. You can write:
$ pi = 3.14; / / php will while $ pi is a real point
$ pi_arrondi = 3 / / php $ pi_arrondi know that is an integer
$ sigle_html = "hypertext markup language"; / / here is a string
Here is a sample script php, performing calculations with variables, which should be fairly simple to understand:
Code:
<? Php
largeur_rectangle = $ 5;
$ longueur_rectangle = 10;
$ surface_rectangle = 5 * 10;
echo "The surface of the rectangle is equal to $ surface_rectangle";
>
Finally, there are variables one particularly because they can keep more data: the tables.
Thus, to illustrate the tables, if I need a variable containing all the days of the week to work with them days later in the script, I may define a table like this:
Code:
<? Php
$ jours_semaine [0] = "Monday";
$ jours_semaine [1] = "Tuesday";
$ jours_semaine [2] = "Wednesday";
$ jours_semaine [3] = "Thursday";
$ jours_semaine [4] = "Friday";
$ jours_semaine [5] = "Saturday";
$ jours_semaine [6] = "Sunday";
>
I can also write (which will return to the same thing):
Code:
<? Php
$ jours_semaine = array ( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
>
One wonders at first sight, what can these arrays, but no worries, you will know quickly enough in handling PHP in practice.
Bookmarks