ABC of HTML/PHP
ULg


Travaux Pratiques du Cours de Bases de Données



Menu



Notes sur HTML

HTML est le langage utilisé pour écrire des pages que l'on peut visualiser à l'aide d'un web browser du type mozila, netscape ou explorer. Vous pouvez toujours avoir accès au code html d'une page internet en utilisaant le menu "View/Page Source" dans mozilla, et "Affichage/Source" dans explorer. Ce qui suit est directement repris du site du NCSA .

Terms to Know

WWW
World Wide Web
Web
World Wide Web
SGML
Standard Generalized Markup Language--a standard for describing markup languages
DTD
Document Type Definition--this is the formal specification of a markup language, written using SGML
HTML
HyperText Markup Language--HTML is an SGML DTD
In practical terms, HTML is a collection of platform-independent styles (indicated by markup tags) that define the various components of a World Wide Web document. HTML was invented by Tim Berners-Lee while at CERN, the European Laboratory for Particle Physics in Geneva.

HTML Documents

What an HTML Document Is

HTML documents are plain-text (also known as ASCII) files that can be created using any text editor (e.g., Emacs or vi on UNIX machines; SimpleText on a Macintosh; Notepad on a Windows machine). You can also use word-processing software if you remember to save your document as "text only with line breaks".

Tags Explained

An element is a fundamental component of the structure of a text document. Some examples of elements are heads, tables, paragraphs, and lists. Think of it this way: you use HTML tags to mark the elements of a file for your browser. Elements can contain plain text, other elements, or both.

To denote the various elements in an HTML document, you use tags. HTML tags consist of a left angle bracket (<), a tag name, and a right angle bracket (>). Tags are usually paired (e.g., <H1> and </H1>) to start and end the tag instruction. The end tag looks just like the start tag except a slash (/) precedes the text within the brackets.

Some elements may include an attribute, which is additional information that is included inside the start tag. For example, you can specify the alignment of images (top, middle, or bottom) by including the appropriate attribute with the image source HTML code. Tags that have optional attributes are noted below.

NOTE: HTML is not case sensitive. <title> is equivalent to <TITLE> or <TiTlE>. There are a few exceptions noted in Escape Sequences below.

Not all tags are supported by all World Wide Web browsers. If a browser does not support a tag, it will simply ignore it. Any text placed between a pair of unknown tags will still be displayed, however.

The Minimal HTML Document

Every HTML document should contain certain standard HTML tags. Each document consists of head and body text. The head contains the title, and the body contains the actual text that is made up of paragraphs, lists, and other elements. Browsers expect specific information because they are programmed according to HTML and SGML specifications.

Required elements are shown in this sample bare-bones document:

    <html>
    <head>

    <TITLE>A Simple HTML Example</TITLE>
    </head>
    <body>
    <H1>HTML is Easy To Learn</H1>
    <P>Welcome to the world of HTML.
    This is the first paragraph. While short it is  
    still a paragraph!</P>

    <P>And this is the second paragraph.</P>
    </body>
    </html>
The required elements are the <html>, <head>, <title>, and <body> tags (and their corresponding end tags). Because you should include these tags in each file, you might want to create a template file with them. (Some browsers will format your HTML file correctly even if these tags are not included. But some browsers won't! So make sure to include them.)

Notes sur PHP

Création/edition fichier

La premiere chose a faire, c'est pouvoir éditer un fichier. Pour cela, vous pouvez utiliser n'importe quel éditeur de texte. L'idéal est évidemment d'avoir un éditeur qui met en évidence la syntaxe de PHP. La solution que je vous propose est d'utiliser EMACS. Malheureusment, sur le réseau 8 (réseau étudiant) le module concernant le mode php n'est pas installé. Par contre, il est installé dans mon répertoire /home/latour/lisp . Pour pouvoir l'utiliser, vous devez placer les lignes suivantes dans votre fichier .emacs (situé dans votre repertoire racine):
; Mode font-lock (couleurs)
(global-font-lock-mode t)
; Mode php
(setq load-path (cons "/home/latour/lisp" load-path))
(require 'php-mode)

Ceci étant fait, pour créer/éditer un fichier, vous n'avez qu'à lancer la commande:
shell> emacs mon_fichier.php
(Les fichiers PHP ont l'extension ".php")

L'ABC sur PHP

L'idée est d'avoir un fichier accessible en lecture à tout le monde dans le répertoire WWW. Par exemple,
/home/latour/WWW/bd/exemple/main.php

Lorsqu'on essaie d'obtenir le fichier par l'intermédiaire d'un browser (mozilla, netscape, explorer,...), en tapant l'URL du fichier, (dans notre exemple, http://www.student.montefiore.ulg.ac.be/~latour/bd/exemple/main.php ) le serveur http, apache dans notre cas, va effectuer l'analyse grammaticale du fichier à l'aide du module php. Le résultat de cette opération est un nouveau fichier qui est directement envoyé au browser.

Lorque le parser php effectue l'analyse gramaticale d'un fichier, il laisse le texte inchangé jusqu'au moment ou il rencontre le tag special <?php . A ce moment, il commence l'interprétation du code PHP. Le parser exécute alors tout le code qu'il trouve jusqu'au tag ?> , qui signale au parser d'envoyer le texte à nouveau inchangé.

Sans rentrer dans les détails, la syntaxe de PHP est similaire à celle du C et plus précisément à celle de Perl ou des langages de script shell. Une caractéristique fondamentale est qu'on ne déclare pas les types des variables. Le parser PHP attribue un type au variable suivant le contexte. (On peut toutefois explicitement donner un type à une expression en utilisant une opération cast). Pour plus d'info, je vous renvoie au site "officiel" de php: php.net

Note importante pour les étudiants du réseau 8 (1LINF,3ELIN,..)
Pour développer vos scripts php, vous pouvez verifier la syntaxe de votre code en utilisant PHP en ligne de commande:
shell> php votre_fichier.php > resultat.html
Vous avez alors le resultat du parser php dans le fichier resultat.html et il indique le premier probleme de syntaxe rencontré...

Références

HTML

PHP

Exemple

Petit exemple: exemple/login.html Pour se loguer, utiliser louis comme login et comme mot de passe. Fichiers de l'exemple: exemple.zip

latour@montefiore.ulg.ac.be