<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Tue, 26 May 2026 06:11:58 +0200 -->

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Derniers articles - STHDA : Public]]></title>
		<atom:link href="https://www.sthda.com/french/syndication/rss/articles/17" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Derniers articles - STHDA : Public]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>fr</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[Transf?rer des fichiers]]></title>
			<link>https://www.sthda.com/french/articles/22-linux/71-transferer-des-fichiers/</link>
			<guid>https://www.sthda.com/french/articles/22-linux/71-transferer-des-fichiers/</guid>
			<description><![CDATA[L'objectif de cet article est de vous montrer comment t?l?charger, transfert des fichiers, synchroniser deux r?pertoires ? partir de linux.<br />
<br />
<h2 class="formatter-title">wget : t?l?chargement de fichiers</h2><br />
<br />
Il suffit d'indiquer l?adresse HTTP ou FTP d'un fichier ? t?l?charger :<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ubuntu-fr.org<span style="color: #000000; font-weight: bold;">/</span>telechargement?<span style="color: #007800;">action</span>=dl</pre></pre></div><br />
<span class="warning">Pour arr?ter le t?l?chargement : Ctrl + c</span><br />
Pour reprendre un t?l?chargement arr?t?, utiliser l'option -c :<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-c</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ubuntu-fr.org<span style="color: #000000; font-weight: bold;">/</span>telechargement?<span style="color: #007800;">action</span>=dl</pre></pre></div><br />
<br />
Lancer un t?l?chargement en tache de fond :<br />
- Utiliser la technique <strong>nohup</strong> qui s'applique ? toutes les commandes<br />
- Utiliser l'option --background<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--background</span> <span style="color: #660033;">-c</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ubuntu-fr.org<span style="color: #000000; font-weight: bold;">/</span>telechargement?<span style="color: #007800;">action</span>=dl</pre></pre></div><br />
<span class="success">wget propose pas mal d'options. Faire man wget pour voir les options. </span><br />
<br />
<h2 class="formatter-title">scp : copier des fichiers ? travers le r?seau</h2><br />
<br />
scp = secure copy<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> fichier_origine copie_destination</pre></pre></div><br />
<strong><span style="color:#000080;">Copier un fichier de votre ordinateur vers un autre :</span></strong><br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> image.png akassambara<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:~<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span></pre></pre></div><br />
<span class="success">Remplacer l'IP par le nom d'h?te</span><br />
<br />
<br />
<strong><span style="color:#000080;">Copier plusieurs fichiers de votre ordinateur vers un autre :</span></strong><br />
<br />
- Utiliser l'option -r (recursif) en pr?cisant le dossier : <br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-r</span> mon_dossier akassambara<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:~<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span></pre></pre></div><br />
<br />
<br />
<strong><span style="color:#000080;">Copier un fichier d'un autre ordinateur vers le v?tre:</span></strong><br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">scp</span> akassambara<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:image.png copie_image_sur_mon_pc.png
<span style="color: #666666; font-style: italic;">#Copier le fichier sans  changer le nom :</span>
<span style="color: #c20cb9; font-weight: bold;">scp</span> akassambara21<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:image.png 
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Si le serveur SSH auquel vous essayez de vous connecter n'est pas sur le port standard (22), il faudra indiquer le num?ro du port avec l'option -P :</span><br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-P</span> <span style="color: #000000;">16296</span> akassambara<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:image.png .</pre></pre></div><br />
<br />
<br />
<h2 class="formatter-title">ftp & sftp : transf?rer des fichiers</h2><br />
Le FTP (File Transfer Protocol) est un protocole permettant d'?changer des fichiers sur le r?seau. La connexion peut se faire en mode anonyme (site public) ou authentifi? (site priv?)<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#Connexion au serveur debian</span>
<span style="color: #c20cb9; font-weight: bold;">ftp</span> ftp.debian.org
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#Afficher le contenu du repertoire </span>
<span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;">#chemin du r?pertoire actuel</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #666666; font-style: italic;"># Changer de r?pertoire</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Transfert des fichiers</h3><br />
<br />
<strong>put</strong> : envoie un fichier vers le server<br />
<strong>get</strong> : t?l?charge un fichier depuis le serveur.<br />
<br />
Vous pouvez par exemple r?cup?rer le fichier README :<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ftp</span> get README </pre></pre></div><br />
<br />
Le fichier est t?l?charg? dans le dossier dans lequel vous vous trouviez sur votre ordinateur.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">ftp</span><span style="color: #000000; font-weight: bold;">></span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;"># Pour savoir dans quel dossier vous ?tes chez vous</span></pre></pre></div><br />
<br />
<span class="warning">Pour quitter la session : Ctrl + D</span><br />
<br />
<h3 class="formatter-title">sftp : Transfert s?curis?</h3><br />
<br />
Requiert un mot de passe<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">sftp <span style="color: #c20cb9; font-weight: bold;">login</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #c20cb9; font-weight: bold;">ip</span></pre></pre></div><br />
<br />
<span class="warning"><br />
Si votre serveur SSH fonctionne sur un autre port, vous devrez le pr?ciser comme ceci : sftp -oPort=27401 login@serveur.<br />
</span><br />
<br />
<h2 class="formatter-title">rsync : synchroniser des fichiers pour une sauvegarde</h2><br />
<br />
<strong><span style="color:#333399;">rsync</span></strong> permet d'effectuer une synchronisation entre deux r?pertoires, que ce soit sur le m?me PC ou entre deux ordinateurs reli?s en r?seau.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">C<span style="color: #ff0000;">'est une sorte de scp intelligent : il compare et analyse les diff?rences entre deux dossiers puis copie uniquement les changements.</span></pre></pre></div><br />
<br />
<h3 class="formatter-title">Synchroniser deux dossiers du m?me ordinateur</h3><br />
<br />
Le contenu du dossier images est sauvegard? dans le dossier backups:<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
rsync <span style="color: #660033;">-arv</span> <span style="color: #660033;">--delete</span> Images<span style="color: #000000; font-weight: bold;">/</span> backups<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><br />
    -a : conserve toutes les informations sur les fichiers, comme les droits (chmod), la date de modification, etc. ;<br />
    -r : sauvegarde aussi tous les sous-dossiers qui se trouvent dans le dossier ? sauvegarder ;<br />
    -v : mode verbeux, affiche des informations d?taill?es sur la copie en cours.<br />
    --delete : pour que le contenu soit strictement identique. Lorsqu'un fichier a ?t? supprimer dans le r?pertoire d'origine, il le sera ?galement dans le r?pertoire de sauvegarde.<br />
</span><br />
<br />
<strong><span style="color:#000080;">Pour mettre les fichiers supprimer dans "un dossier corbeille" au cas ou : </span></strong><br />
Ajouter l'option : --backup --backup-dir=~/kass/backups_supprimes<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
 rsync <span style="color: #660033;">-arv</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--backup</span> <span style="color: #660033;">--backup-dir</span>=~<span style="color: #000000; font-weight: bold;">/</span>kass<span style="color: #000000; font-weight: bold;">/</span>backups_supprimes Images<span style="color: #000000; font-weight: bold;">/</span> backups<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Indiquer le chemin absolu du dossier corbeille pour ?viter des probl?mes</span><br />
<br />
<h3 class="formatter-title">Sauvegarder sur un autre ordinateur</h3><br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
rsync <span style="color: #660033;">-arv</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--backup</span> <span style="color: #660033;">--backup-dir</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>kassambara<span style="color: #000000; font-weight: bold;">/</span>fichiers_supprimes Images<span style="color: #000000; font-weight: bold;">/</span> mateo21<span style="color: #000000; font-weight: bold;">@</span>IP_du_serveur:mes_backups<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;</pre></pre></div><br />
<br />
Si votre serveur SSH ?coute sur un autre port que celui par d?faut, il faudra rajouter -e "ssh -p port" :<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
rsync <span style="color: #660033;">-arv</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--backup</span> <span style="color: #660033;">--backup-dir</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>kass<span style="color: #000000; font-weight: bold;">/</span>fichiers_supprimes Images<span style="color: #000000; font-weight: bold;">/</span> kass<span style="color: #000000; font-weight: bold;">@</span>IP_du_serveur:mes_backups<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p 12473"</span>
&nbsp;</pre></pre></div>]]></description>
			<pubDate>Fri, 03 Oct 2014 16:14:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Connaitre les capacit?s de l'ordinateur]]></title>
			<link>https://www.sthda.com/french/articles/22-linux/69-connaitre-les-capacites-de-l-ordinateur/</link>
			<guid>https://www.sthda.com/french/articles/22-linux/69-connaitre-les-capacites-de-l-ordinateur/</guid>
			<description><![CDATA[<h2 class="formatter-title">RAM</h2><br />
<br />
La commande free peut ?tre utilis?e pour conna?tre la RAM. Les options -b, -k, -m, -g donnent la m?moire en KB, MB ou GB<br />
<br />
L'option -t affiche la RAM totale+SWAP<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">free</span> <span style="color: #660033;">-tg</span>
&nbsp;</pre></pre></div><br />
<br />
<h2 class="formatter-title">Taille des disques</h2><br />
<br />
Utiliser la commande df -h<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-h</span>
&nbsp;</pre></pre></div><br />
<br />
<h2 class="formatter-title">Version de linux</h2><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
lsb_release <span style="color: #660033;">-a</span>
&nbsp;</pre></pre></div><br />
<br />
<h2 class="formatter-title">32 ou 64 bits</h2><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">uname</span> <span style="color: #660033;">-a</span>
&nbsp;</pre></pre></div><br />
<br />
<h2 class="formatter-title">Afficher le nombre de coeurs processeur sous Linux</h2><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'model name'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>cpuinfo <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span>
&nbsp;</pre></pre></div>]]></description>
			<pubDate>Wed, 24 Sep 2014 09:51:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[La console Linux]]></title>
			<link>https://www.sthda.com/french/articles/22-linux/66-la-console-linux/</link>
			<guid>https://www.sthda.com/french/articles/22-linux/66-la-console-linux/</guid>
			<description><![CDATA[[page]La console et les commandes de base[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">O? se trouve la console</h3><br />
<br />
<strong>Sous KDE</strong> : Rechercher <strong>Konsole</strong> dans le lanceur graphique<br />
<strong>Sous Unity</strong>: Rechercher <strong>Terminal</strong> dans le lanceur graphique<br />
<br />
<span class="notice">Pour acc?der ? distance ? distance ? un ordinateur (ou serveur) sous linux, on utilise le protocole SSH. PuTTY est un logiciel Windows qui permet d'acc?der ? une machine Linux depuis windows via le protocole SSH.</span><br />
<br />
<h3 class="formatter-title">Symboles affich?s sur la console</h3><br />
<br />
$: compte utilisateur normal avec des droits limit?s<br />
#: mode super-utilisateur<br />
<br />
<h3 class="formatter-title">Commandes et param?tres</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #666666; font-style: italic;">#Affiche la date</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#Liste les fichiers et dossiers du r?pertoire actuel </span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-a</span> <span style="color: #666666; font-style: italic;">#Affiche tout le contenu du dossier, m?me les fichiers cach?s</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> Examples <span style="color: #666666; font-style: italic;">#Affiche le contenu du dossier Examples</span>
<span style="color: #c20cb9; font-weight: bold;">clear</span> <span style="color: #666666; font-style: italic;">#Efface le contenu de la console</span>
<span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;">#Affiche le r?pertoire courant</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">pwd et which: O? suis-je?</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;">#renvoie le r?pertoire courant</span>
<span style="color: #c20cb9; font-weight: bold;">which</span> mysql <span style="color: #666666; font-style: italic;">#Renvoie l'emplacement du programme mysql (/usr/bin/mysql)</span>
<span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;">#Renvoie l'emplacement de la commande pwd (/bin/pwd)</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Lister les fichiers et dossiers</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#Affiche la liste des fichiers et dossier du r?pertoire courant</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-a</span> <span style="color: #666666; font-style: italic;">#Afficher tous les fichiers et dossiers cach?s</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-F</span> <span style="color: #666666; font-style: italic;">#Rajoute ? la fin des ?l?ments un symbole pour qu'on puisse faire la distinction entre les dossiers, fichiers</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #666666; font-style: italic;">#Liste d?taill?e (droits, nombre de liens physiques, propri?taire, groupe, taille en octets, date de derni?re modification, nom du fichier ou dossier)</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lh</span> <span style="color: #666666; font-style: italic;">#Liste d?taill?e avec la taille indiqu?e en Ko, Mo, Go. (NB: h=human readable)</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lt</span> <span style="color: #666666; font-style: italic;">#Trier par date de derni?re modification</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">En pratique, il est pr?f?rable de combiner -t avec -r. Ce qui renverse l'ordre d'affichage des fichiers afin d'avoir le dernier fichier modifi? en bas de la liste, c'est plus pratique ? l'usage dans la console.</span><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-larth</span> <span style="color: #666666; font-style: italic;">#contient toutes les options que j'aime</span></pre></pre></div><br />
<br />
<h3 class="formatter-title">cd: Changer de dossier</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#Aller ? la racine</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> usr<span style="color: #000000; font-weight: bold;">/</span>games <span style="color: #666666; font-style: italic;">#Aller dans le dossier games</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> .. <span style="color: #666666; font-style: italic;">#Revenir au dossier pr?c?dent (usr)</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>.. <span style="color: #666666; font-style: italic;">#Permet de reculer de deux dossiers parents</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~ <span style="color: #666666; font-style: italic;">#Retour au r?pertoire parent </span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Le nom du dossier peut ?tre automatiquement compl?t? par la console. Taper par exemple : cd /usr/ga puis appuyer sur Tab. La commande est compl?t?e ? cd /usr/games</span><br />
<br />
<h3 class="formatter-title">du: taille occup?e par les dossiers </h3><br />
<br />
<strong>du</strong>: disk usage<br />
<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span>  <span style="color: #666666; font-style: italic;">#on se place dans le r?pertoire home</span>
<span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #666666; font-style: italic;">#Affiche la taille en octets des dossiers (uniquement) du r?pertoire actuel</span>
<span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-h</span> <span style="color: #666666; font-style: italic;">#taille pour les humains (en Ko, Mo, Go)</span>
<span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-a</span> <span style="color: #666666; font-style: italic;">#Affiche la taille des dossiers ET des fichiers</span>
<span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-sh</span> <span style="color: #666666; font-style: italic;">#Affiche la taille totale occup?e par le dossier actuel.</span>
&nbsp;</pre></pre></div><br />
<br />
[page]Manipuler les fichiers[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">cat & less : afficher un fichier </h3><br />
<br />
<h4 class="formatter-title">cat : afficher tout le fichier</h4><br />
<br />
Nous allons travailler sur un fichier qui existe d?j? : syslog (dans le dossier /var/log).<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log <span style="color: #666666; font-style: italic;">#on se place dans le dossier log</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#affiche le contenu du dossier log</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> syslog <span style="color: #666666; font-style: italic;">#Affiche tout le contenu du fichier  syslog dans la console d'un coup</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #660033;">-n</span> syslog <span style="color: #666666; font-style: italic;">#Affiche le contenu du fichier en indiquant le num?ro de ligne</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">La commande <strong>cat</strong> vous envoie tout le fichier ? la figure. Elle est plus adapt?e lorsque l'on travaille sur de petits fichiers que sur des gros.</span><br />
<br />
<h4 class="formatter-title">less : afficher le fichier page par page</h4><br />
<br />
<strong>less</strong> affiche progressivement le contenu du fichier, page par page<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">less</span> syslog
&nbsp;</pre></pre></div><br />
<br />
Pour lire la suite, il y a des raccourcis clavier ? connaitre:<br />
<br />
<ul class="formatter-ul">
<li class="formatter-li">Espace : Affiche la suite du fichier.
</li><li class="formatter-li">Entr?e : Affiche la ligne suivante.Vous pouvez aussi utiliser la fl?che vers le bas.
</li><li class="formatter-li">d : affiche les onze lignes suivantes (soit une moiti? d'?cran).
</li><li class="formatter-li">b : retourne en arri?re d'un ?cran.
</li><li class="formatter-li">y : retourne d'une ligne en arri?re. Vous pouvez aussi appuyer sur la touche Fl?che vers le haut.
</li><li class="formatter-li">u : retourne en arri?re d'une moiti? d'?cran (onze lignes).
</li><li class="formatter-li">q : arr?te la lecture du fichier. Cela met fin ? la commande less.<br />
</li></ul><br />
<br />
<h4 class="formatter-title">Quelques raccourcis plus avanc?s</h4><br />
<br />
<ul class="formatter-ul">
<li class="formatter-li">= : indique o? vous en ?tes dans le fichier (num?ro des lignes affich?es et pourcentage).
</li><li class="formatter-li">h : affiche l'aide (toutes les commandes que je vous apprends ici, je les tire de l?). Tapez q pour sortir de l'aide.
</li><li class="formatter-li">/ : tapez / suivi du texte que vous recherchez pour lancer le mode recherche. Faites Entr?e pour valider. Pour ceux qui savent s'en servir, sachez que les expressions r?guli?res sont accept?es.
</li><li class="formatter-li">n : apr?s avoir fait une recherche avec /, la touche n vous permet d'aller ? la prochaine occurrence de votre recherche.
</li><li class="formatter-li">N : pareil que n, mais pour revenir en arri?re.<br />
</li></ul><br />
<br />
<h3 class="formatter-title">head & tail : afficher le d?but et la fin d'un fichier </h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log <span style="color: #666666; font-style: italic;">#on se place dans le dossier log</span>
<span style="color: #c20cb9; font-weight: bold;">head</span> syslog <span style="color: #666666; font-style: italic;">#Affiche juste les premi?res lignes du fichier. Ne permet pas de se d?placer dans le fichier comme less</span>
<span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> syslog <span style="color: #666666; font-style: italic;">#Affiche les 3 premi?res lignes du fichier</span>
<span style="color: #c20cb9; font-weight: bold;">tail</span> syslog <span style="color: #666666; font-style: italic;">#affiche les derni?res lignes du fichier</span>
<span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> <span style="color: #666666; font-style: italic;">#Affiche les 3 derni?res lignes du fichier</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Il y a un autre param?tre pour tail: -f (f pour follow). Ce param?tre ordonne ? tail de ? suivre ? la fin du fichier au fur et ? mesure de son ?volution. C'est un bon moyen de surveiller ce qui se passe en temps r?el sur un ordinateur. </span><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> syslog</pre></pre></div><br />
<br />
<span class="success">Faites Ctrl + C (Ctrl et C en m?me temps) pour arr?ter la commande tail.</span><br />
<br />
Par exemple, les logs Apache du Site permettent de voir en temps r?el qui se connecte sur le site, avec quelle IP, quel fichier a ?t? charg?, ? quelle heure, etc.<br />
<br />
<span class="notice">Notez que par d?faut, tail -f recherche les nouveaux changements dans le fichier toutes les secondes. Si vous voulez, vous pouvez rajouter le param?tre -s suivi d'un nombre. Par exemple, tail -f -s 3 syslog recherchera les changements toutes les trois secondes (plut?t que toutes les secondes).</span><br />
<br />
<h3 class="formatter-title">touch & mkdir : cr?er des fichiers et dossiers </h3><br />
<br />
La commande touch est ? la base faite pour modifier la date de derni?re modification d'un fichier. Si le fichier n'existe pas, il sera cr??.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #666666; font-style: italic;"># on se place dans le home</span>
<span style="color: #c20cb9; font-weight: bold;">touch</span> fichier1.txt <span style="color: #666666; font-style: italic;"># cr?ation du fichier 1</span>
<span style="color: #c20cb9; font-weight: bold;">touch</span> fichier1.txt fichier2.txt <span style="color: #666666; font-style: italic;">#Cr?ation de deux fichiers en m?me temps</span>
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #ff0000;">"mon fichier.txt"</span> <span style="color: #666666; font-style: italic;"># le nom du fichier contient des espaces</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> dossier1.txt <span style="color: #666666; font-style: italic;">#cr?ation du dossier</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> dossier1.txt dossier2.txt <span style="color: #666666; font-style: italic;">#Cr?ation de deux dossiers en m?me temps</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> animaux<span style="color: #000000; font-weight: bold;">/</span>vertebres<span style="color: #000000; font-weight: bold;">/</span>chat <span style="color: #666666; font-style: italic;"># Le param?tre -p sert ? cr?er des dossiers interm?diaires (animaux puis vertebres dans animaux, puis chat dans vertebres). </span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">cp & mv : copier et d?placer un fichier </h3><br />
<br />
<h4 class="formatter-title">cp: copier des fichiers</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#copier dans le m?me dossier</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> fichier1.txt fichier1_copie.txt <span style="color: #666666; font-style: italic;"># param?tre 1: nom du fichier ? copier; param?tre 2: nom de la copie</span>
<span style="color: #666666; font-style: italic;">#copier dans un autre dossier</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> fichier1.txt mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#fichier1.txt est copier vers "mondossier" sous le m?me nom</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> fichier1.txt mondossier<span style="color: #000000; font-weight: bold;">/</span>fichier2.txt <span style="color: #666666; font-style: italic;"># fichier1.txt est copier vers "mondossier" sous le nom fichier2.txt</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">Copier des dossiers</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#Avec l'option -R, vous pouvez copier un dossier, ainsi que tous les sous-dossiers et fichiers qu'il contient !</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> dossier1 dossier2 <span style="color: #666666; font-style: italic;">#dossier1 est copi? sous le nom dossier2</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">Utiliser le joker</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">*</span>.jpg mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;"># Copier tous les fichiers image .jpg dans un sous-dossier</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> so<span style="color: #000000; font-weight: bold;">*</span> mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#Copier tous les fichiers dont le nom commence par ? so ?</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">mv: Renommer/D?placer un fichier</h4><br />
<br />
<span class="success">mv s'utilise pratiquement comme cp et permet de d?placer ou de renommer un fichier/dossier</span><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mv</span> fichier1.txt fichier2.txt <span style="color: #666666; font-style: italic;">#renommer un fichier</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> fichier1.txt mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#fichier1.txt est d?placer vers un sous-dossier</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> fichier1.txt mondossier<span style="color: #000000; font-weight: bold;">/</span>fichier2.txt <span style="color: #666666; font-style: italic;"># fichier1.txt est d?placer dans le sous-dossier avec changement de nom</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">*</span>.jpg mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#d?place tous les fichiers image .jpg dans un sous-dossier</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">rm : supprimer des fichiers et dossiers</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> fichier1.txt <span style="color: #666666; font-style: italic;"># supprime le fichier</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> fichier1.txt fichier2.txt <span style="color: #666666; font-style: italic;"># supprime plusieurs fichiers en m?me temps</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-i</span> fichier1.txt <span style="color: #666666; font-style: italic;"># Demande une confirmation lors de la suppression</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> fichier1.txt <span style="color: #666666; font-style: italic;"># Force la suppression quoi qu'il arrive</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-v</span> fichier1.txt <span style="color: #666666; font-style: italic;"># Verbose (parle beaucoup), montre l'avancement</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-r</span> dossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#supprime un dossier et son contenu</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #666666; font-style: italic;">#supprime tous les fichiers et sous-dossiers du dossier dans lequel je me trouve</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">ln -s : Cr?er des liens symboliques entre fichiers</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> fichier1.txt fichier2.txt <span style="color: #666666; font-style: italic;">#fichier 2 repr?sente un raccourci de fichier 1</span>
&nbsp;</pre></pre></div><br />
<br />
[page]Les utilisateurs et les droits [/page]<br />
<br />
<h4 class="formatter-title">sudo: ex?cuter une commande en root </h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#ex?cuter une commande en tant que root</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #666666; font-style: italic;">#devenir root et le rester</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success">Pour quitter le ? mode root ?, tapez exit (ou faites la combinaison Ctrl + D).</span><br />
<br />
<h3 class="formatter-title">adduser : gestion des utilisateurs</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
adduser patrick <span style="color: #666666; font-style: italic;">#ajout de l'utilisateur patrick; le mot de pass vous sera demand?</span>
<span style="color: #c20cb9; font-weight: bold;">passwd</span> patrick <span style="color: #666666; font-style: italic;">#changer le mot de passe de patrick</span>
deluser patrick <span style="color: #666666; font-style: italic;">#supprime l'utilisateur patrick sans confirmation</span>
deluser <span style="color: #660033;">--remove-home</span> patrick<span style="color: #666666; font-style: italic;"># supprime le repertoire personnel de patrick</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">addgroup : gestion des groupes </h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
addgroup amis <span style="color: #666666; font-style: italic;">#ajouter un groupe d'utilisateur</span>
usermod <span style="color: #660033;">-g</span> amis patrick <span style="color: #666666; font-style: italic;">#ajouter patrick dans le groupe amis</span>
usermod <span style="color: #660033;">-g</span> patrick patrick <span style="color: #666666; font-style: italic;">#remettre patrick dans le groupe patrick comme il l'?tait avant</span>
delgroup amis <span style="color: #666666; font-style: italic;"># supprime le groupe amis</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Il est aussi possible de faire en sorte qu'un utilisateur appartienne ? plusieurs groupes. Pour ce faire, utilisez le param?tre -G (majuscule).<br />
Exemple : usermod -G amis,paris,collegues patrick.<br />
S?parez les noms des groupes par une virgule, sans espace entre chaque nom de groupe.<br />
</span><br />
<br />
<span class="error"><br />
Faites tr?s attention en utilisant usermod ! Lorsque vous avez recours ? -G, l'utilisateur change de groupe et ce peu importe les groupes auxquels il appartenait auparavant.<br />
Si vous voulez ajouter des groupes ? un utilisateur (sans perdre les groupes auxquels il appartenait avant cela), utilisez -a :<br />
usermod -aG amis patrick<br />
</span><br />
<br />
<span class="success">addgroup et delgroup n'existent que sous Debian et ses d?riv?s (m?me remarque que pour adduser et deluser).<br />
Les commandes ? traditionnelles ? qui fonctionnent partout sont groupadd et groupdel, mais elles offrent moins d'options.</span><br />
<br />
<h3 class="formatter-title">chown: gestion des propri?taires d'un fichier </h3><br />
<br />
Commande utilis?e en tant que root<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chown</span> patrick rapport.txt <span style="color: #666666; font-style: italic;">#patrick devient le propri?taire du fichier</span>
<span style="color: #c20cb9; font-weight: bold;">chgrp</span> amis rapport.txt <span style="color: #666666; font-style: italic;">#changer le groupe propri?taire d'un fichier</span>
<span style="color: #666666; font-style: italic;">#chown peut aussi changer le groupe propri?taire d'un fichier</span>
<span style="color: #c20cb9; font-weight: bold;">chown</span> patrick:amis rapport.txt <span style="color: #666666; font-style: italic;">#Cela affectera le fichier ? l'utilisateur patrick et au groupe amis.</span>
<span style="color: #666666; font-style: italic;">#-R : affecter r?cursivement les sous-dossiers</span>
<span style="color: #666666; font-style: italic;">#donner tout le contenu du dossier personnel de patrick ? mateo21 (et au groupe mateo21)</span>
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> mateo21:mateo21 <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>patrick<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">chmod : modifier les droits d'acc?s </h3><br />
<br />
<h4 class="formatter-title">Le fonctionnement des droits</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666;">mateo21@mateo21-desktop:~$ </span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span>
total <span style="color: #000000;">40</span>
drwxr-xr-x <span style="color: #000000;">2</span> mateo21 mateo21 <span style="color: #000000;">4096</span> <span style="color: #000000;">2007</span>-<span style="color: #000000;">11</span>-<span style="color: #000000;">13</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">53</span> Desktop
drwxr-xr-x <span style="color: #000000;">2</span> mateo21 mateo21 <span style="color: #000000;">4096</span> <span style="color: #000000;">2007</span>-<span style="color: #000000;">11</span>-<span style="color: #000000;">13</span> <span style="color: #000000;">13</span>:<span style="color: #000000;">46</span> Documents
&nbsp;</pre></pre></div><br />
<br />
On peut voir cinq lettres diff?rentes. Voici leur signification :<br />
<br />
    <strong>d</strong> (Directory) : indique si l'?l?ment est un dossier ;<br />
   <strong> l</strong> (Link) : indique si l'?l?ment est un lien (raccourci) ;<br />
   <strong> r </strong>(Read) : indique si on peut lire l'?l?ment ;<br />
    <strong>w </strong>(Write) : indique si on peut modifier l'?l?ment ;<br />
    <strong>x </strong>(eXecute) : si c'est un fichier, ? x ? indique qu'on peut l'ex?cuter. Ce n'est utile que pour les fichiers ex?cutables (programmes et scripts).<br />
  <br />
Si la lettre appara?t, c'est que le droit existe. S'il y a un tiret ? la place, c'est qu'il n'y a aucun droit.<br />
<br />
Les droits sont d?coup?s en fonction des utilisateurs:<br />
 <img src="https://www.sthda.com/french/french/upload/droit_linux.png" alt="" /><br />
<br />
<ul class="formatter-ul">
<li class="formatter-li">le premier triplet rwx indique les droits que poss?de le propri?taire du fichier sur ce dernier ;
</li><li class="formatter-li">le second triplet rwx indique les droits que poss?dent les autres membres du groupe sur ce fichier ;
</li><li class="formatter-li">enfin, le dernier triplet rwx indique les droits que poss?dent tous les autres utilisateurs de la machine sur le fichier.<br />
</li></ul><br />
<br />
<h4 class="formatter-title">chmod : modifier les droits d'acc?s</h4><br />
    <br />
<strong>Attribuer des droits avec des chiffres (chmod absolu)</strong><br />
<br />
<table class="formatter-table">
<tr class="formatter-table-row">
<th class="formatter-table-head">Droit</th>
                <th class="formatter-table-head">Chiffre</th>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">r</td>
<td class="formatter-table-col">4</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">w</td>
<td class="formatter-table-col">2</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">x</td>
<td class="formatter-table-col">1</td>
</tr>
</table><br />
<br />
Si vous voulez combiner ces droits, il va falloir additionner les chiffres correspondants.<br />
<br />
Voici la liste des droits possibles et la valeur correspondante :<br />
<br />
<!-- START HTML -->

<table >
<thead>
<tr>
<th>
<p>Droits</p>
</th>
<th>
<p>Chiffre</p>
</th>
<th>
<p>Calcul</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>---</p>
</td>
<td>
<p>0</p>
</td>
<td>
<p>0 + 0 + 0</p>
</td>
</tr>
<tr>
<td>
<p>r--</p>
</td>
<td>
<p>4</p>
</td>
<td>
<p>4 + 0 + 0</p>
</td>
</tr>
<tr>
<td>
<p>-w-</p>
</td>
<td>
<p>2</p>
</td>
<td>
<p>0 + 2 + 0</p>
</td>
</tr>
<tr>
<td>
<p>--x</p>
</td>
<td>
<p>1</p>
</td>
<td>
<p>0 + 0 + 1</p>
</td>
</tr>
<tr>
<td>
<p>rw-</p>
</td>
<td>
<p>6</p>
</td>
<td>
<p>4 + 2 + 0</p>
</td>
</tr>
<tr>
<td>
<p>-wx</p>
</td>
<td>
<p>3</p>
</td>
<td>
<p>0 + 2 + 1</p>
</td>
</tr>
<tr>
<td>
<p>r-x</p>
</td>
<td>
<p>5</p>
</td>
<td>
<p>4 + 0 + 1</p>
</td>
</tr>
<tr>
<td>
<p>rwx</p>
</td>
<td>
<p>7</p>
</td>
<td>
<p>4 + 2 + 1</p>
</td>
</tr>
</tbody>
</table>

<!-- END HTML --><br />
<br />
Par exemple, ? 640 ? indique les droits du propri?taire, du groupe et des autres (dans l'ordre).<br />
<br />
    6 : droit de lecture et d'?criture pour le propri?taire.<br />
    4 : droit de lecture pour le groupe.<br />
    0 : aucun droit pour les autres.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> rapport.txt
&nbsp;</pre></pre></div><br />
<br />
<strong>Attribuer des droits avec des lettres (chmod relatif)</strong><br />
<br />
Dans ce mode, il faut savoir que :<br />
    <strong>u</strong> = user (propri?taire) ;<br />
    <strong>g</strong> = group (groupe) ;<br />
    <strong>o</strong> = other (autres).<br />
<br />
 et que :<br />
<br />
    + signifie : ? Ajouter le droit ? ;<br />
    - signifie : ? Supprimer le droit ? ;<br />
    = signifie : ? Affecter le droit ?.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> g+<span style="color: #c20cb9; font-weight: bold;">w</span> rapport.txt <span style="color: #666666; font-style: italic;"># Ajouter le droit d'?criture au groupe</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> o-r rapport.txt <span style="color: #666666; font-style: italic;">#Enlever le droit de lecture aux autres</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> g+<span style="color: #c20cb9; font-weight: bold;">w</span>,o-w rapport.txt <span style="color: #666666; font-style: italic;">#Ajouter le droit d'?criture au groupe et l'enlever aux autres</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> go-r rapport.txt <span style="color: #666666; font-style: italic;">#Enlever le droit de lecture au groupe et aux autres </span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x rapport.txt <span style="color: #666666; font-style: italic;">#Ajouter le droit d'ex?cution ? tout le monde</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #007800;">u</span>=rwx,<span style="color: #007800;">g</span>=r,<span style="color: #007800;">o</span>=- rapport.txt <span style="color: #666666; font-style: italic;">#Affecter tous les droits au propri?taire, juste la lecture au groupe, rien aux autres</span>
&nbsp;</pre></pre></div><br />
<br />
<strong>Et toujours? -R pour affecter r?cursivement</strong><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> <span style="color: #000000;">700</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>mateo21
&nbsp;</pre></pre></div><br />
<br />
[page]Nano, ?diteur de texte du d?butant[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Demarrage</h3><br />
<br />
Pour d?marrer le logiciel, il vous suffit simplement de taper nano dans la console :<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span></pre></pre></div><br />
<br />
D?s lors, vous pouvez commencer ? taper du texte.<br />
<br />
Voici les raccourcis les plus importants :<br />
    Ctrl + G : afficher l'aide ;<br />
    Ctrl + K : couper la ligne de texte (et la mettre dans le presse-papier) ;<br />
    Ctrl + U : coller la ligne de texte que vous venez de couper ;<br />
    Ctrl + C : afficher ? quel endroit du fichier votre curseur est positionn? (num?ro de ligne?) ;<br />
    Ctrl + W : rechercher dans le fichier ;<br />
    Ctrl + O : enregistrer le fichier (?crire) ;<br />
    Ctrl + X : quitter Nano.<br />
<br />
<h3 class="formatter-title">Les param?tres de la commande Nano</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">nano</span> salut.txt <span style="color: #666666; font-style: italic;">#ouvre le fichier</span>
&nbsp;</pre></pre></div><br />
<br />
<ul class="formatter-ul">
<li class="formatter-li"><strong>-m</strong>: autorise l'utilisation de la souris sous Nano.
</li><li class="formatter-li"><strong>-i</strong>: indentation automatique. L'alin?a (tabulations) de la ligne pr?c?dente sera respect? lorsque vous irez ? la ligne. Tr?s utile lorsque vous ?ditez un fichier de code source.
</li><li class="formatter-li"><strong>-A</strong>: active le retour intelligent au d?but de la ligne.<br />
</li></ul><br />
<br />
Lancer <strong>nano</strong> avec toutes les options:<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #660033;">-miA</span> salut.txt</pre></pre></div><br />
<br />
<h3 class="formatter-title">Configurer nano avec .nanorc</h3><br />
<br />
Chaque utilisateur de la machine peut cr?er son propre fichier de configuration .nanorc dans son r?pertoire personnel (home) : /home/personnel/.nanorc. <br />
<br />
<span class="notice">Les fichiers commen?ant par un point sont des fichiers de configuration. Ils sont cach?s. Pour les afficher, il faut utiliser la commande ls -a.</span><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">nano</span> .nanorc <span style="color: #666666; font-style: italic;"># cr?ation du fichier</span>
<span style="color: #000000; font-weight: bold;">set</span> mouse <span style="color: #666666; font-style: italic;">#Activation de la souris</span>
<span style="color: #000000; font-weight: bold;">set</span> autoindent <span style="color: #666666; font-style: italic;">#Pour ?viter d'avoir ? taper -i. Indentation automatique.</span>
<span style="color: #000000; font-weight: bold;">set</span> smarthome <span style="color: #666666; font-style: italic;">#Pour ?viter d'avoir ? taper -A. Retour ? la ligne intelligent</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Le nanorc global et la coloration syntaxique</h3><br />
<br />
Il existe un fichier nanorc <strong>global</strong> qui est pris en compte pour tous les utilisateurs: /etc/nanorc. Il contient toutes les options disponibles, mais elles sont pr?c?d?es d'un # qui signifie qu'il s'agit d'un commentaire. Il sufit de decommenter les options d'int?r?ts.<br />
<br />
Vers la fin du fichier, vous verrez une section appel?e  <strong>color setup</strong>, qui commence par ces lignes-l? :<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">## Nanorc files</span>
<span style="color: #666666; font-style: italic;"># include "/usr/share/nano/nanorc.nanorc"</span>
<span style="color: #666666; font-style: italic;">## C/C++</span>
<span style="color: #666666; font-style: italic;"># include "/usr/share/nano/c.nanorc"</span>
<span style="color: #666666; font-style: italic;">## HTML</span>
<span style="color: #666666; font-style: italic;"># include "/usr/share/nano/html.nanorc"</span>
&nbsp;</pre></pre></div><br />
<br />
Je vous invite ? d?commenter toutes les lignes d'include. Cela permettra d'activer la coloration ? intelligente ? de vos fichiers selon leur type.<br />
<br />
[page]Installer des programmes avec apt-get [/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
Sous linux, les programmes sont regroup?s sur des serveurs appel?s d?pots.<br />
<br />
Le fichier ? ouvrir qui contient la liste des d?p?ts:<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list</pre></pre></div><br />
<br />
Il existe des outils graphiques pour ?diters les sources de d?pots:<br />
Ubuntu : allez dans Syst?me &#8594; Administration &#8594; Sources de logiciels ;<br />
KUbuntu : allez dans Menu K &#8594; Syst?me &#8594; Gestionnaire Adept &#8594; Adept &#8594; G?rer les d?p?ts ;<br />
<br />
<strong>Nous devons g?n?ralement suivre trois ?tapes pour t?l?charger un paquet :</strong><br />
<br />
   <span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#Installation</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get update</span> <span style="color: #666666; font-style: italic;">#(optionnel) : pour mettre notre cache ? jour si ce n'est pas d?j? fait ;</span>
<span style="color: #c20cb9; font-weight: bold;">apt-cache search</span> monpaquet <span style="color: #666666; font-style: italic;">#(optionnel) : pour rechercher le paquet que nous voulons t?l?charger si nous ne connaissons pas son nom exact ;</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get install</span> monpaquet <span style="color: #666666; font-style: italic;"># pour t?l?charger et installer notre paquet.</span>
<span style="color: #666666; font-style: italic;">#d?sinstallation</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get remove</span> monpaquet <span style="color: #666666; font-style: italic;">#desinstalle un paquet</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get autoremove</span>  monpaquet <span style="color: #666666; font-style: italic;">#desinstalle mon paquet ainsi que les d?pendances devenues inutiles.</span>
<span style="color: #666666; font-style: italic;">#mise ? jour</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get upgrade</span> <span style="color: #666666; font-style: italic;">#met ? jour tous les paquets install?s</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<span class="notice">Les commandes pr?c?dentes doivent ?tre utilis?es en tant que root.</span><br />
<br />
<span class="success"><br />
Astuce : vous pouvez installer plusieurs paquets d'un coup en les listant un ? un :<br />
apt-get install paquet1 paquet2 paquet3<br />
</span><br />
<br />
[page]Manuel d'une commande[/page]<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">man</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #666666; font-style: italic;">#Affiche le manuel d'une commande</span>
<span style="color: #c20cb9; font-weight: bold;">apropos</span> sound <span style="color: #666666; font-style: italic;">#Rechercher toutes les commandes qui parlent de son</span>
&nbsp;</pre></pre></div><br />
<br />
[page]Rechercher des fichiers[/page]<br />
<br />
La commande <strong>locate</strong> fait une recherche rapide dans la base de donn?es des fichiers. <br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">locate</span> monfichier.txt <span style="color: #666666; font-style: italic;">#recherche rapide</span></pre></pre></div><br />
<br />
<span class="notice">La base de donn?es est mise ? jour par le syst?me une fois par jour. Pour que la recherche tienne compte d'un fichier qui vient d'?tre cr??, il faut mettre ? jour le syst?me en utilisant la commande: sudo updatedb</span><br />
<br />
La commande <strong>find</strong> fait une recherche approfondie des fichiers actuellement pr?sents sur le disque dur.<br />
<br />
<strong>Fonctionnement de la commande find</strong><br />
<br />
find ? o? ? ? quoi ? ? que faire avec ?<br />
<br />
<ul class="formatter-ul">
<li class="formatter-li"> <strong>O?</strong> : c'est le nom du dossier dans lequel la commande va faire la recherche. Par d?faut, si ce param?tre n'est pas pr?cis?, la recherche s'effectuera dans le dossier courant et ses sous-dossiers.
</li><li class="formatter-li"><strong>Quoi </strong>: c'est le fichier ? rechercher. On peut rechercher un fichier par son nom, mais aussi en fonction de la date de sa cr?ation, de sa taille, etc. Ce param?tre est obligatoire.
</li><li class="formatter-li"> <strong>Que faire avec </strong>: il est possible d'effectuer des actions automatiquement sur chacun des fichiers trouv?s. L'action la plus courante consiste ? afficher simplement la liste des fichiers trouv?s, mais nous verrons que nous pouvons faire bien d'autres choses.  Par d?faut, la commande find affiche les r?sultats trouv?s et ne fait rien d'autre avec.<br />
</li></ul>]]></description>
			<pubDate>Sun, 16 Feb 2014 09:12:00 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R2XLSX : lire, ?crire et formater un document Excel dans R]]></title>
			<link>https://www.sthda.com/french/articles/7-r/60-r2xlsx-lire-ecrire-et-formater-un-document-excel-dans-r/</link>
			<guid>https://www.sthda.com/french/articles/7-r/60-r2xlsx-lire-ecrire-et-formater-un-document-excel-dans-r/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
R2XLSX est un fichier  contenant un ensemble de fonctions R, que j'ai ?crite, permettant de lire et ?crire un fichier Excel dans R de mani?re simple et rapide. Il offre ?galement la possibilit? d'ajouter des graphiques et de formater les donn?es. <br />
<br />
<br />
<h3 class="formatter-title">Installation</h3><br />
<br />
Pour pouvoir utiliser les fonctions contenues dans le fichier R2XLSX, vous devez ex?cuter le code suivant ? chaque session R. Les fonctions d?pendent du package <strong>xlsx</strong>. Le package xlsx est automatiquement install? par le script dans le cas o? il n'existe pas.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"https://www.sthda.com/french/upload/r2xlsx.r"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Les fonctions disponibles</h3><br />
<ul class="formatter-ul">
	<li class="formatter-li"><strong>xlsx.addPlot</strong> pour ajouter un graphique.
	</li><li class="formatter-li"><strong>xlsx.addParagraph</strong> pour ajouter un paragraphe de textes
	</li><li class="formatter-li"><strong>xlsx.addTable</strong> pour ajouter des tables.
	</li><li class="formatter-li"><strong>xlsx.addHeader</strong> pour ajouter des titres.
	</li><li class="formatter-li"><strong>xlsx.addLineBreak</strong> pour ajouter un saut de ligne.
	</li><li class="formatter-li"><strong>xlsx.addHyperlink</strong> pour ajouter un lien hypertext.
	</li><li class="formatter-li"><strong>xlsx.readFile</strong> pour lire un fichier excel.
	</li><li class="formatter-li"><strong>xlsx.writeFile</strong> pour ?crire un fichier excel.
        </li><li class="formatter-li"><strong>xlsx.openFile</strong> pour ouvrir le fichier excel.<br />
<br />
</li></ul><br />
<br />
<h3 class="formatter-title">Votre premier document Excel</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"https://www.sthda.com/french/upload/r2xlsx.r"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#create an Excel workbook. Both .xls and .xlsx file formats can be used.</span>
filename <span style="color: #080;"><-</span> <span style="color: #ff0000;">"Example1.xlsx"</span>
wb <span style="color: #080;"><-</span> createWorkbook<span style="color: #080;">&#40;</span>type<span style="color: #080;">=</span><span style="color: #ff0000;">"xlsx"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#Create a sheet in that workbook to contain the table</span>
sheet <span style="color: #080;"><-</span> createSheet<span style="color: #080;">&#40;</span>wb, sheetName <span style="color: #080;">=</span> <span style="color: #ff0000;">"example1"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add header</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Add table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add Text :Author</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb, sheet, 
             value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author : Alboukadel KASSAMBARA. <span style="color: #000099; font-weight: bold;">\n</span>@:alboukadel.kassambara@gmail.com.<span style="color: #000099; font-weight: bold;">\n</span> Website : http://ww.sthda.com"</span>,
             isItalic<span style="color: #080;">=</span>TRUE, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkgray"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">3</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add table</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#saving a workbook to an Excel file and writes the file to disk.</span>
saveWorkbook<span style="color: #080;">&#40;</span>wb, filename<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#View the file</span>
xlsx.<span style="">openFile</span><span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>
&nbsp;
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:521px; height:258px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_first_document.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Ajout de titre</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Header</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#header level 1</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 1"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 2</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 2"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 3</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 3"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 4</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 4"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">4</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 5</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 5"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 6</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 6"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">6</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:266px; height:133px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_header.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajout de textes </h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
&nbsp;
<span style="color: #228B22;"># Add texts</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#Add Text :Author</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author : Alboukadel KASSAMBARA. <span style="color: #000099; font-weight: bold;">\n</span>@:alboukadel.kassambara@gmail.com.<span style="color: #000099; font-weight: bold;">\n</span> Website : http://ww.sthda.com"</span>,
             isItalic<span style="color: #080;">=</span>TRUE, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkgray"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">3</span><span style="color: #080;">&#41;</span><span style="color: #228B22;"># Three line breaks</span>
&nbsp;
<span style="color: #228B22;">#Add paragraph</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add paragraph"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
paragraph<span style="color: #080;">=</span><span style="color: #ff0000;">"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged."</span>
<span style="color: #228B22;">#customized</span>
xlsx.<span style="">addParagraph</span><span style="color: #080;">&#40;</span>wb, sheet, paragraph, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span>, isItalic<span style="color: #080;">=</span>TRUE, 
                  fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkred"</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"gray"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:437px; height:263px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_text.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Ajouter un hyperlien</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Header</span>
<span style="color: #228B22;">#**************************************</span>
&nbsp;
<span style="color: #228B22;">#Add Hyperlink</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add Hyperlink"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addHyperlink</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">"https://www.sthda.com"</span>, <span style="color: #ff0000;">"Click-me!!"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:231px; height:74px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_hyperlink.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajouter une table</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
&nbsp;
<span style="color: #228B22;">#Add table</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#add iris data using default settings</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Add table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#header</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Simple Table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Customized table : column data format</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Customized table : font color and size"</span>,
               level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>,
              fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkblue"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">"16"</span>             
<span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:519px; height:421px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajouter un graphique</h3><br />
<br />
<h4 class="formatter-title">Boxplot basic</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Add Plot</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#boxplot</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">ToothGrowth</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add Plot"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
plotFunction<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span><span style="color: #0000FF; font-weight: bold;">boxplot</span><span style="color: #080;">&#40;</span>len ~ dose, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> <span style="color: #CC9900; font-weight: bold;">ToothGrowth</span>,
                                 <span style="color: #0000FF; font-weight: bold;">subset</span> <span style="color: #080;">=</span> supp <span style="color: #080;">==</span> <span style="color: #ff0000;">"VC"</span>, <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"yellow"</span>,
                                 main <span style="color: #080;">=</span> <span style="color: #ff0000;">"Guinea Pigs' Tooth Growth"</span>,
                                 xlab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Vitamin C dose mg"</span>, ylab <span style="color: #080;">=</span> <span style="color: #ff0000;">"tooth length"</span>,
                                 xlim <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0.5</span>, <span style="color: #ff0000;">3.5</span><span style="color: #080;">&#41;</span>, ylim <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>, <span style="color: #ff0000;">35</span><span style="color: #080;">&#41;</span>, yaxs <span style="color: #080;">=</span> <span style="color: #ff0000;">"i"</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span>wb, sheet, plotFunction<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:442px; height:397px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_boxplot.png"/></div></center>
<!-- END HTML --><br />
<br />
<h4 class="formatter-title">GGPLOT2 : Courbe de densit?</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create workbook and sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Add Plot</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#ggplot2</span>
rquery.<span style="">loadPackages</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"ggplot2"</span><span style="color: #080;">&#41;</span><span style="color: #228B22;">#for plot</span>
<span style="color: #0000FF; font-weight: bold;">set.<span style="">seed</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">1234</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">df</span> <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">data.<span style="">frame</span></span><span style="color: #080;">&#40;</span>cond <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">factor</span><span style="color: #080;">&#40;</span> <span style="color: #0000FF; font-weight: bold;">rep</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"A"</span>,<span style="color: #ff0000;">"B"</span><span style="color: #080;">&#41;</span>, each<span style="color: #080;">=</span><span style="color: #ff0000;">200</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>, 
                 rating <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">200</span><span style="color: #080;">&#41;</span>,<span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">200</span>, <span style="color: #0000FF; font-weight: bold;">mean</span><span style="color: #080;">=</span>.8<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># Density plots with semi-transparent fill</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">"Density plots with semi-transparent fill"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
gg.<span style="">p</span><span style="color: #080;"><-</span>ggplot<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">df</span>, aes<span style="color: #080;">&#40;</span>x<span style="color: #080;">=</span>rating, fill<span style="color: #080;">=</span>cond<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> <span style="color: #080;">+</span> geom_density<span style="color: #080;">&#40;</span>alpha<span style="color: #080;">=</span>.3<span style="color: #080;">&#41;</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span><span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&#40;</span>gg.<span style="">p</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:436px; height:395px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_ggplot2.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Lire un fichier Excel</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">file</span> <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">system.<span style="">file</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"tests"</span>, <span style="color: #ff0000;">"test_import.xlsx"</span>, package <span style="color: #080;">=</span> <span style="color: #ff0000;">"xlsx"</span><span style="color: #080;">&#41;</span>
res <span style="color: #080;"><-</span> xlsx.<span style="">readFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">file</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;"># read first sheet</span>
<span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span>res<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Ecrire un fichier Excel</h3><br />
<br />
LA fonction suivante permet d'?crire une table de donn?es dans un fichier excel.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
res <span style="color: #080;"><-</span> xlsx.<span style="">writeFile</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">USArrests</span>, <span style="color: #0000FF; font-weight: bold;">file</span><span style="color: #080;">=</span><span style="color: #ff0000;">"USArrests.xlsx"</span>, sheetName<span style="color: #080;">=</span><span style="color: #ff0000;">"USArrests"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Un document Excel complet</h3><br />
<br />
<span class="success">Le script complet utilis? pour cr?e le document word suivant est t?l?chargeable ici : <a href="https://www.sthda.com/french/french/upload/howtouse_r2xlsx.r">howToUse_R2XLSX.R</a></span><br />
<br />
Le fichier Excel est t?l?chargeable en cliquant sur le lien suivant:<a href="https://www.sthda.com/french/french/upload/r2xlsx_example1.xlsx">R2XLSX_Example1.xlsx</a><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/r2xlsx_example1.pdf" class="embed" >Document Excel complet</a>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Utilisation avanc?e - prototype des fonctions</h3><br />
<br />
Les prototypes des fonctions sont montr?es ci-dessous pour une utilisation avanc?e.<br />
<br />
<h4 class="formatter-title">xlsx.addHeader</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add header :sheet title and subtitle</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : your header value</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#rowBreak : number of rows to jump before appending the data</span>
<span style="color: #228B22;">#underline : a numeric value specifying the thickness of the underline.</span>
<span style="color: #228B22;">#Allowed values are 0, 1, 2.</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                         startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">1</span>,<span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addText</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Text : add a simple line text</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#the function is similar to xlsx.addParagraph</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#backGroundColor : fill color of the cell</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#colSpan : number of column to be merged (paragraph : width)</span>
<span style="color: #228B22;">#rowSpan : number of rows to be merged corresponding to paragrath height</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb,sheet, value, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE,
                            startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.addParagraph</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add paragraph</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#backGroundColor : fill color of the cell</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#colSpan : number of column to be merged (paragraph : width)</span>
<span style="color: #228B22;">#rowSapn : number of rows to be merged corresponding to paragrath height</span>
xlsx.<span style="">addParagraph</span><span style="color: #080;">&#40;</span>wb,sheet, value, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE,
                            startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">10</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addHyperlink</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Hyperlink</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
xlsx.<span style="">addHyperlink</span><span style="color: #080;">&#40;</span>wb,sheet, address, friendlyName, 
                            fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"blue"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE, startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span> 
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addLineBreak</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Line break to the sheet</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : your header value</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#numberOfLine : number of rows to jump before appending the data</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, numberOfLine<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addTable</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#add table </span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#data : data frame</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#rowBreak : nimber of rows to jum before appending the data</span>
<span style="color: #228B22;">#if col.names and row.names : column and row names  are written</span>
<span style="color: #228B22;">#fontColor : color of text</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#rownamesFill: background color of table row names</span>
<span style="color: #228B22;">#colnamesFill : background color of table column names</span>
<span style="color: #228B22;">#rowFill : background color of pair rows (i.e : 2, 4, 6). For table styling.</span>
<span style="color: #228B22;">#mergedColumnForRownames : number of column to merge for rownames. </span>
<span style="color: #228B22;">#Be carrefull : using mergedColumnForRownames is a  very slow process</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">data</span>, startRow<span style="color: #080;">=</span>NULL,startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>,
                        col.<span style="">names</span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">row.<span style="">names</span></span><span style="color: #080;">=</span>TRUE, columnWidth<span style="color: #080;">=</span><span style="color: #ff0000;">14</span>,
                        fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, rownamesFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>, colnamesFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>, rowFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>,
                        mergedColumnForRownames<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>,   ...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.addPlot</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#add Plot </span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#plotFunction: plot function</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span> wb, sheet, plotFunction, startRow<span style="color: #080;">=</span>NULL,startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>,
               width<span style="color: #080;">=</span><span style="color: #ff0000;">480</span>, height<span style="color: #080;">=</span><span style="color: #ff0000;">480</span>,... <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.writeFile</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Write a data.frame to an Excel workbook</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#data : data frame</span>
<span style="color: #228B22;">#file : output file name</span>
<span style="color: #228B22;">#if col.names and row.names : column and row names  are written</span>
<span style="color: #228B22;">#append :if TRUE data should be appended to an existing file. </span>
<span style="color: #228B22;">#usage : res <- xlsx.writeFile(USArrests, file="USArrests.xlsx", sheetName="USArrests")</span>
xlsx.<span style="">writeFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">data</span>, <span style="color: #0000FF; font-weight: bold;">file</span>, sheetName<span style="color: #080;">=</span><span style="color: #ff0000;">"Sheet1"</span>,
               col.<span style="">names</span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">row.<span style="">names</span></span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">append</span><span style="color: #080;">=</span>FALSE, ...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.readFile</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Read a data.frame from an Excel workbook</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#file :the path to the file to read</span>
<span style="color: #228B22;">#sheetIndex: a number representing the sheet index in the workbook.</span>
<span style="color: #228B22;">#startRow : index of starting row</span>
<span style="color: #228B22;">#colIndex: a numeric vector indicating the cols you want to extract. If NULL, all columns found will be extracted</span>
<span style="color: #228B22;">#endRow: The index of the last row to pull. If NULL, read all the rows in the sheet.</span>
<span style="color: #228B22;">#header : if TRUE, the first row is considered as row names</span>
<span style="color: #228B22;">#usage : </span>
<span style="color: #228B22;">#file <- system.file("tests", "test_import.xlsx", package = "xlsx")</span>
<span style="color: #228B22;">#res <- xlsx.readFile(file, 1)  # read first sheet</span>
<span style="color: #228B22;">#head(res)</span>
xlsx.<span style="">readFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">file</span>, sheetIndex<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, startRow<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, colIndex<span style="color: #080;">=</span>NULL, endRow<span style="color: #080;">=</span>NULL, header<span style="color: #080;">=</span>TRUE,...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.openFile</h4><br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#Open file</span>
<span style="color: #228B22;">#++++++++++++++++++++++++++++</span>
xlsx.<span style="">openFile</span><span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<br />
<h3 class="formatter-title">Voir aussi</h3><br />
<a href="https://www.sthda.com/french/french/articles/articles-7-36+xlconnect-lire-ecrire-et-manipuler-des-fichiers-microsoft-excel-a-partir-de-r.php">XLConnect: lire, ?crire et manipuler des fichiers Microsoft Excel ? partir de R</a>]]></description>
			<pubDate>Sun, 28 Jul 2013 07:35:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R2DOCX : Cr?er un document word avec R]]></title>
			<link>https://www.sthda.com/french/articles/7-r/57-r2docx-creer-un-document-word-avec-r/</link>
			<guid>https://www.sthda.com/french/articles/7-r/57-r2docx-creer-un-document-word-avec-r/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
Deux possibilit?s pour g?n?rer un document word. Soit avec <a href="http://yihui.name/knitr/demo/pandoc/">Knitr et pandoc</a> ou avec <a href="https://github.com/davidgohel/R2DOCX">R2DOCX</a>.<br />
<br />
<h3 class="formatter-title">Pandoc : Convertir un document Markdown vers d'autres formats</h3><br />
<br />
Pour plus de d?tails <a href="http://yihui.name/knitr/demo/pandoc/">cliquez-ici</a><br />
<br />
La fonction pandoc() est incluse dans le package knitr (version 1.2) permettant de convertir des documents Markdown ? d'autres formats tels que Latex/PDF, HTML et word (.doc, .docx).<br />
<br />
Cette fonction permet juste d?ex?cuter de mani?re simple la ligne de commande suivante:<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
FILE <span style="color: #080;"><-</span> <span style="color: #ff0000;">"example"</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span>paste0<span style="color: #080;">&#40;</span><span style="color: #ff0000;">"pandoc -o "</span>, FILE, <span style="color: #ff0000;">".docx "</span>, FILE, <span style="color: #ff0000;">".md"</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Pour le fichier.md, le chemin absolu est necessaire. <br />
Utilisez donc la commande :<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
commande<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"pandoc -o "</span>,  <span style="color: #ff0000;">"myfile.docx "</span>, <span style="color: #0000FF; font-weight: bold;">getwd</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>, <span style="color: #ff0000;">"/myfile.md "</span>, sep<span style="color: #080;">=</span><span style="color: #ff0000;">""</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span>commande<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
</span><br />
<br />
Pour installer pandoc <a href="http://johnmacfarlane.net/pandoc/index.html">suivre ce lien</a><br />
<br />
<strong><span style="color:blue;">Utilisation simple</span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>knitr<span style="color: #080;">&#41;</span>
pandoc<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'html'</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;"># HTML</span>
pandoc<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'latex'</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;"># LaTeX/PDF</span>
pandoc<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'docx'</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;"># MS Word</span>
pandoc<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'odt'</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;"># OpenDocument</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Cr?er un document word avec R2DOCX</h3><br />
<br />
R2DOCX permet de cr?er, de mani?re simple, un document word ? partir d'un template ou pas, d'ins?rer des graphiques et des tables.<br />
<br />
Une documentation est compl?te est fournie <a href="https://github.com/davidgohel/R2DOCX">ici</a><br />
Un exemple est montr? <a href="http://blog.revolutionanalytics.com/2013/06/create-word-documents-from-r-with-r2docx.html">ici</a><br />
<br />
 <h4 class="formatter-title">Installation</h4> <br />
<br />
<strong>Compatibilit? R >= 3.0</strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"devtools"</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOC'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOCX'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Pour les utilisateurs de Mac :</span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">setenv</span></span><span style="color: #080;">&#40;</span>NOAWT<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;">#prevents usage of awt.[http://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Java-_0028OS-X_0029]</span>
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"devtools"</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOC'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOCX'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Les fonctions disponibles</h4> <br />
<ul class="formatter-ul">
<li class="formatter-li"><strong>addPlot</strong> pour ajouter un graphique.
</li><li class="formatter-li"><strong>addParagraph</strong> pour ajouter un paragraphe de textes
</li><li class="formatter-li"><strong>addTable</strong> pour ajouter des tables.
</li><li class="formatter-li"><strong>addHeader</strong> pour ajouter des titres.
</li><li class="formatter-li"><strong>addTOC</strong> pour ajouter une table des mati?res.
</li><li class="formatter-li"><strong>addPageBreak</strong> pour ajouter un saut de page.
</li><li class="formatter-li"><strong>addLineBreak</strong> pour ajouter un saut de ligne.
</li><li class="formatter-li"><strong>replaceText</strong> pour remplacer du texte.<br />
</li></ul><br />
<br />
 <h4 class="formatter-title">Votre premier document</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">setenv</span></span><span style="color: #080;">&#40;</span>NOAWT<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;">#prevents usage of awt - required on Mac</span>
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>R2DOCX<span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Nom du fichier ? cr?er</span>
docx.<span style="">file</span> <span style="color: #080;"><-</span> <span style="color: #ff0000;">"document.docx"</span>
<span style="color: #228B22;"># Objet Docx ? manipuler</span>
doc <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">new</span> <span style="color: #080;">&#40;</span><span style="color: #ff0000;">"Docx"</span>, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#ajouter une table</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc, <span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">10</span>,<span style="color: #080;">&#93;</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Ajouter du texte</span>
doc <span style="color: #080;"><-</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Hello World!"</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># ajouter un graphique</span>
doc <span style="color: #080;">=</span> addPlot<span style="color: #080;">&#40;</span> doc, <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span> <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>
               , width <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span>, height <span style="color: #080;">=</span> <span style="color: #ff0000;">8</span>
<span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Ecriture du fichier </span>
writeDoc<span style="color: #080;">&#40;</span> doc, docx.<span style="">file</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Cr?er un document word ? partir d'un template</h4> <br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># document word ? cr?er</span>
docx.<span style="">file</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"document.docx"</span>
<span style="color: #228B22;"># Document word ? utiliser comme template</span>
template.<span style="">file</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">file.<span style="">path</span></span><span style="color: #080;">&#40;</span> find.<span style="">package</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"R2DOCX"</span><span style="color: #080;">&#41;</span>, <span style="color: #ff0000;">"templates/TEMPLATE_01.docx"</span>, fsep <span style="color: #080;">=</span> <span style="color: #ff0000;">"/"</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Cr?er un nouveau objet</span>
doc <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"Docx"</span>
, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> 
, basefile <span style="color: #080;">=</span> template.<span style="">file</span>
<span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Dans le document de base, 2 mots cl?s existent- Rempla?ons les</span>
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#40;</span> doc, pattern <span style="color: #080;">=</span> <span style="color: #ff0000;">"AUTHOR"</span>, replacement <span style="color: #080;">=</span> <span style="color: #ff0000;">"John Doe"</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#40;</span> doc, pattern <span style="color: #080;">=</span> <span style="color: #ff0000;">"DATE"</span>, replacement <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">date</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Titre principal</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#Titre principale</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Exemple"</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"TitleDoc"</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span> <span style="color: #228B22;">#saut de page</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:500px; height:70px"><img src="https://www.sthda.com/french/french/upload/r2docx_titre.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Table des mati?res</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#Table des mati?re (table of content : TOC)</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#On vous demandera de mettre ? jour la table de mati?res</span>
<span style="color: #228B22;">#la pr?mi?re fois que le document sera ouvert</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Table des mati?res"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addTOC<span style="color: #080;">&#40;</span>doc<span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span><span style="color: #228B22;">#saut de page</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:520px; height:185px"><img src="https://www.sthda.com/french/french/upload/r2docx_toc.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Ajout de textes (Normal et liste)</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajout de textes (normal and liste)</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset presentation"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
<span style="color: #228B22;">#texte normal</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Dataset 'measured.weights' is set of weights measurements collected on few people before savate training."</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#liste non ordonn?e</span>
texts <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"Column 'gender' is the subject gender."</span> 
           , <span style="color: #ff0000;">"Column 'id' is the unique subject identifier."</span> 
           , <span style="color: #ff0000;">"Column 'cat' is the subject weight category."</span> 
           , <span style="color: #ff0000;">"Column 'competitor' tells wether or not subject practice competition."</span> 
           , <span style="color: #ff0000;">"Column 'day' is the day of measurement."</span> 
           , <span style="color: #ff0000;">"Column 'weight' is the measured weight."</span> 
<span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> texts, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"BulletList"</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:515px; height:220px"><img src="https://www.sthda.com/french/french/upload/r2docx_texte.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Formatage conditionnel du texte</h4> <br />
<br />
La fonction <strong>addParagraph</strong> permet d'ajouter simplement du texte comme montr? ci-dessus. Elle peut ?galement ?tre utilis?e pour faire du remplacement de textes et du formatage conditionnel.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># template text</span>
x <span style="color: #080;">=</span> <span style="color: #ff0000;">"[animal] eats [food]."</span>
<span style="color: #228B22;"># define formatting properties for replacement text ? see chapter "styles"</span>
textProp <span style="color: #080;">=</span> textProperties<span style="color: #080;">&#40;</span> color <span style="color: #080;">=</span> <span style="color: #ff0000;">"blue"</span> <span style="color: #080;">&#41;</span>
replacement.<span style="">styles</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> animal<span style="color: #080;">=</span> textProp, food<span style="color: #080;">=</span> textProp <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># define replacement text</span>
replacements <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> animal <span style="color: #080;">=</span> <span style="color: #ff0000;">"donkey"</span>, food <span style="color: #080;">=</span> <span style="color: #ff0000;">"grass"</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;"><-</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> x, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span>
                     , replacements <span style="color: #080;">=</span> replacements
                     , replacement.<span style="">styles</span> <span style="color: #080;">=</span> replacement.<span style="">styles</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:218px; height:45px"><img src="https://www.sthda.com/french/french/upload/r2docx_replacement.png"/></div></center>
<!-- END HTML --><br />
<br />
<span class="notice"><strong>La fonction textProperties</strong><br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">textProperties<span style="color: #080;">&#40;</span>color <span style="color: #080;">=</span> <span style="color: #ff0000;">"black"</span>, font.<span style="">size</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span>
, font.<span style="">weight</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"normal"</span>, font.<span style="">style</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"normal"</span>
, font.<span style="">family</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Arial"</span> <span style="color: #080;">&#41;</span></pre></pre></div><br />
<br />
<strong>color</strong>: couleur de la police; <strong>font.size</strong>: taille en pixel; <strong>font.weight</strong> : "normal" ou "bold"; <strong>font.style</strong>: "normal" ou "italic"; <strong>font.family</strong>: police.<br />
</span><br />
 <h4 class="formatter-title">Ajouter une table</h4> <br />
<br />
<strong><span style="color:blue;">Table simple: </span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajouter une table</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;"># Table utilisee</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span> measured.<span style="">weights</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset first lines"</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
<span style="color: #228B22;">#Table simple</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc
                , <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span> measured.<span style="">weights</span>, n <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span> <span style="color: #080;">&#41;</span>
                , formats <span style="color: #080;">=</span> get.<span style="">light</span>.<span style="">formats</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addLineBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span><span style="color: #228B22;">#saut de ligne</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:511px; height:278px"><img src="https://www.sthda.com/french/french/upload/r2docx_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Renommer les ent?tes de la table:</span></strong><br />
<br />
<strong>Avant</strong> d'avoir renomm? :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:312px; height:147px"><img src="https://www.sthda.com/french/french/upload/r2docx_table2.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong>Apr?s</strong> avoir renomm? :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc
, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span>
, header.<span style="">labels</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subject Identifier"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Average Weight"</span>
, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Regularity"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Number of visits"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Last visit"</span>
<span style="color: #080;">&#41;</span> <span style="color: #228B22;"># columns labels to display</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:462px; height:182px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_header_label.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Table simple personnalis?e avec fusion des lignes :</span></strong><br />
<br />
Dans la table ci-dessous, les lignes sont fusionn?es sur la colonne 'day'. La colonne 'gender' est color?e en fonction du genre.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># simple addTable with row merging on 'day' column</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset last lines"</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
sampledata <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">tail</span><span style="color: #080;">&#40;</span> measured.<span style="">weights</span><span style="color: #080;">&#91;</span> <span style="color: #0000FF; font-weight: bold;">order</span><span style="color: #080;">&#40;</span>measured.<span style="">weights</span>$day<span style="color: #080;">&#41;</span>, <span style="color: #080;">&#93;</span>, n <span style="color: #080;">=</span> <span style="color: #ff0000;">20</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc
, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> sampledata
, span.<span style="">columns</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"day"</span><span style="color: #080;">&#41;</span>
, col.<span style="">colors</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"gender"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">ifelse</span><span style="color: #080;">&#40;</span> sampledata$gender <span style="color: #080;">==</span> <span style="color: #ff0000;">"male"</span> , <span style="color: #ff0000;">"#00c2ff"</span>, <span style="color: #ff0000;">"#ffcdd1"</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:311px; height:453px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_merge_row.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Table personnalis?e avec ent?tes group?es:</span></strong><br />
<br />
Dans cette table les ent?tes ont ?t? renomm?es, des ent?tes group?es sont cr?es, le type des colonnes est pr?cis? (%, entier, caract?re, nombre d?cimal, date). Les valeurs de la colonne "Regularity" ont ?t? color?es en fonction de la valeur (couleur grise si < 0.5 et bleu si >= 0.5).<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># customized table</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset summary"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc
, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span>
, header.<span style="">labels</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subject Identifier"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Average Weight"</span>
, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Regularity"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Number of visits"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Last visit"</span>
<span style="color: #080;">&#41;</span> <span style="color: #228B22;"># columns labels to display</span>
, grouped.<span style="">cols</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"id"</span>
, <span style="color: #ff0000;">"Summary"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"avg.weight"</span>,  <span style="color: #ff0000;">"regularity"</span>, <span style="color: #ff0000;">"visit.n"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">&#41;</span> 
<span style="color: #080;">&#41;</span> <span style="color: #228B22;"># grouped headers line to add before headers line</span>
, col.<span style="">types</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"character"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"double"</span>
, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"percent"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"integer"</span>
, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"date"</span> <span style="color: #080;">&#41;</span> <span style="color: #228B22;"># reporting types of each columns </span>
, col.<span style="">fontcolors</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">ifelse</span><span style="color: #080;">&#40;</span> weights.<span style="">summary</span>$regularity <span style="color: #080;"><</span> <span style="color: #ff0000;">0.5</span> , <span style="color: #ff0000;">"gray"</span>, <span style="color: #ff0000;">"blue"</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span> <span style="color: #228B22;"># customized font colors for column "regularity"</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:530px; height:266px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_customized.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Ajouter un graphique</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajouter un grahique</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Graphics"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addPlot<span style="color: #080;">&#40;</span> doc,
               <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">boxplot</span><span style="color: #080;">&#40;</span>measured.<span style="">weights</span>$weight ~ measured.<span style="">weights</span>$id,
                                  xlab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subjects"</span>, ylab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Weights"</span> , <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"#0088cc"</span>,
                                  <span style="color: #0000FF; font-weight: bold;">legend</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My boxplot"</span><span style="color: #080;">&#41;</span>,
               width<span style="color: #080;">=</span><span style="color: #ff0000;">7</span>, height<span style="color: #080;">=</span><span style="color: #ff0000;">7</span>
              <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:516px; height:534px"><img src="https://www.sthda.com/french/french/upload/r2docx_plot.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Remplacement de texte</h4> <br />
<br />
Pour remplacer le mot cl? "AUTHOR", dans le document word, avec "Pearson" :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#40;</span> doc, <span style="color: #ff0000;">"AUTHOR"</span>, <span style="color: #ff0000;">"Pearson"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Les styles de titres disponibles dans votre document</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">new</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"Docx"</span>, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> <span style="color: #080;">&#41;</span>
styles<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># [1] "Normal"                  "Titre1"                  "Titre2"                 </span>
<span style="color: #228B22;"># [4] "Titre3"                  "Titre4"                  "Titre5"                 </span>
<span style="color: #228B22;"># [7] "Titre6"                  "Titre7"                  "Titre8"                 </span>
<span style="color: #228B22;">#[10] "Titre9"                  "Policepardfaut"          "TableauNormal"          </span>
<span style="color: #228B22;"># ...</span>
doc <span style="color: #080;"><-</span> setHeaderStyle<span style="color: #080;">&#40;</span>doc, stylenames <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"Titre1"</span>, <span style="color: #ff0000;">"Titre2"</span>, <span style="color: #ff0000;">"Titre3"</span>, <span style="color: #ff0000;">"Titre4"</span>, <span style="color: #ff0000;">"Titre5"</span>, <span style="color: #ff0000;">"Titre6"</span>, <span style="color: #ff0000;">"Titre7"</span>, <span style="color: #ff0000;">"Titre8"</span>, <span style="color: #ff0000;">"Titre9"</span> <span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span> 
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span> doc, <span style="color: #ff0000;">"title 1"</span>, <span style="color: #ff0000;">1</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Un document word complet</h4> <br />
<br />
<span class="success">Le script complet utilis? pour cr?e le document word suivant est t?l?chargeable ici : <a href="https://www.sthda.com/french/french/upload/r2docx.r">R2DOCX.r</a></span><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/r2docx_word.pdf" class="embed" >Document word complet</a>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Voir Aussi</h4> <br />
<br />
<a href="https://www.sthda.com/french/french/articles/articles-7-60+r2xlsx-lire-ecrire-et-formater-un-document.php">R2XLSX : lire, ?crire et formater un document Excel dans R </a>]]></description>
			<pubDate>Sat, 06 Jul 2013 08:26:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Site Web avec PHP et MySQL]]></title>
			<link>https://www.sthda.com/french/articles/20-php/55-site-web-avec-php-et-mysql/</link>
			<guid>https://www.sthda.com/french/articles/20-php/55-site-web-avec-php-et-mysql/</guid>
			<description><![CDATA[[page]Programmes n?cessaires[/page]<br />
<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<strong>Apache</strong> : Serveur web d?livrant les pages web aux visiteurs<br />
<strong>PHP</strong> : Plugin Apache traitant les pages dynamiques<br />
<strong>MySQL</strong> : Logiciel de gestion des bases de donn?es<br />
<br />
Nul besoin d'installer ces progammes individuellement. Des packs existent regroupant Apache + PHP + MySQL.<br />
<br />
<h3 class="formatter-title">Sous windows : Installer WAMP </h3><br />
<br />
<a href="http://telecharger.tomsguide.fr/WAMP5,0301-4008.html">Cliquez ici</a> pour l'installation.<br />
<br />
Lorsque vous d?marrer WAMP, une ic?ne apparait dans la barre des taches.<br />
<br />
WAMP est par d?faut en anglais. Pour changer la langue, click droit -> langage -> french<br />
<br />
Cr?ez un projet web dans c:/wamp/www et nommer le test.<br />
<br />
Pour lancer la page d'accueil : click gauche -> localhost. Votre projet devrait ?tre pr?sent dans la section projet.<br />
<br />
<h3 class="formatter-title">Sous MACOSX : Installer MAMP </h3><br />
<br />
<a href="http://www.mamp.info/en/index.html">Cliquez ici</a> pour l'installation.<br />
<br />
Vous avez la possibilt? de configurer le r?pertoire dans lequel Apache ira chercher les fichiers PHP de votre site web.<br />
<br />
D?marrez MAMP -> Bouton pr?f?rences -> Onglet Apache ->choisir->r?pertoire du site<br />
<br />
Vous pouvez visualiser le contenu de votre site en vous rendant ? l'adresse <a href="http://localhost:8888/votre_site/.">http://localhost:8888/votre_site/.</a><br />
<br />
<br />
<h3 class="formatter-title">Sous LINUX : Installer XAMP </h3><br />
<br />
<a href="http://www.apachefriends.org/fr/xampp.html">Cliquez ici</a> pour l'installation.<br />
<br />
Pour demarre XAMP, taper lacommande : /opt/lampp/lampp start<br />
<br />
Les fichiers PHP devront ?tre plac?s dans le r?pertoire /opt/lampp/htdocs. Vous pouvez y cr?er un sous-r?pertoire tests pour vos premiers tests.<br />
<br />
Vous pouvez y acc?der depuis votre navigateur ? l'adresse suivante : <a href="http://localhost/tests.">http://localhost/tests.</a><br />
<br />
<h3 class="formatter-title">Utiliser un bon ?diteur de fichiers</h3><br />
<br />
Sous Windows : <a href="http://notepad-plus-plus.org/">Notepad++</a><br />
<br />
Sous Mac OSX : <a href="http://www.barebones.com/products/TextWrangler/download.html">TextWrangler</a><br />
<br />
Sous Linux : gedit<br />
<br />
[page]Les bases de PHP[/page]<br />
<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
PHP est un langage utilis? pour concevoir des sites web dynamiques contenant des espaces membres, forum, des actualit?s, des newsletter etc. Vous trouverez dans cet article un m?mento des fonctions cl?s de PHP et MySQL. Cet article a ?t? cr?? ? partir des cours sur PHP  faits par Mathieu Nebra sur le site du z?ro.<br />
<br />
<h3 class="formatter-title">Structure minimale</h3><br />
<br />
Le code PHP s'?crit entre les balises :<strong><?php  VOTRE CODE ICI ?></strong>  et s'ins?rer au milieu du code HTML.<br />
<br />
<span class="notice"><br />
Pour faire des commentaires dans le code, il suffit d'utiliser // ou /* */.<br />
// : Commentaire sur une ligne<br />
/* Votre commentaire ici */ : Commentaire sur plusieurs lignes<br />
</span><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Canard'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// Affichage d'un texte</span>
<span style="color: #0000FF; font-weight: bold;">print</span> <span style="color: #808080;">'Canard'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//idem, Affichage d'un texte</span>
<span style="color: #008000; font-style: italic;">/*Les commentaires longs ici . */</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Notez bien que chaque ligne de code se termine avec un point-virgule ";"</span><br />
<br />
<h3 class="formatter-title">Les variables</h3><br />
<br />
Les variables permettent de garder de l'information en m?moire. <strong>Le nom d'une variable est toujours pr?c?d? par le symbole $</strong><br />
<br />
 <h4 class="formatter-title">Types de variables</h4> <br />
5 types de variables existent :<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$mon_age</span> <span style="color: #8000FF;">=</span> <span style="color: #FF8000;">25</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//Un entier (type int)</span>
<span style="color: #000080;">$mon_nom</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">"pearson"</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//cha?ne de caract?re (type string)</span>
<span style="color: #000080;">$mon_poids</span><span style="color: #8000FF;">=</span><span style="color:#800080;">60.5</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//Nombre d?cimal (type float)</span>
<span style="color: #008000; font-style: italic;">//type bool?en (pour dire si une variable est vrai ou pas)</span>
<span style="color: #000080;">$je_suis_majeur</span> <span style="color: #8000FF;">=</span> <span style="">true</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//bool</span>
<span style="color: #000080;">$je_suis_mineur</span><span style="color: #8000FF;">=</span><span style="">false</span><span style="color: #8000FF;">;</span><span style="color: #008000; font-style: italic;">//bool</span>
<span style="color: #000080;">$pas_de_valeur</span><span style="color: #8000FF;">=</span><span style="">NULL</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// Variable vide</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Affichage et concat?nation des variables</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$mon_age</span><span style="color: #8000FF;">=</span><span style="color: #FF8000;">25</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'mon ?ge est : '</span><span style="color: #8000FF;">.</span><span style="color: #000080;">$mon_age</span><span style="color: #8000FF;">.</span><span style="color: #808080;">' ans'</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success">Ce code affichera : "mon ?ge est 25 ans"</span><br />
<br />
 <h4 class="formatter-title">Calculs simples</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Calculs simples</span>
<span style="color: #008000; font-style: italic;">// $resultat prend ? chaque fois le r?sultat de l'op?ration</span>
<span style="color: #000080;">$resultat</span><span style="color: #8000FF;">=</span><span style="color: #FF8000;">10</span><span style="color: #8000FF;">+</span><span style="color: #FF8000;">5</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//Addition</span>
<span style="color: #000080;">$resultat</span><span style="color: #8000FF;">=</span><span style="color: #FF8000;">10</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">5</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//Multiplication</span>
<span style="color: #000080;">$resultat</span><span style="color: #8000FF;">=</span><span style="color: #FF8000;">10</span><span style="color: #8000FF;">/</span><span style="color: #FF8000;">5</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//Division</span>
<span style="color: #000080;">$resultat</span><span style="color: #8000FF;">=</span><span style="color: #FF8000;">10</span><span style="color: #8000FF;">-</span><span style="color: #FF8000;">5</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//Soustraction</span>
<span style="color: #000080;">$resultat</span><span style="color: #8000FF;">=</span><span style="color: #8000FF;">&#40;</span><span style="color: #FF8000;">10</span><span style="color: #8000FF;">-</span><span style="color: #FF8000;">5</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">2</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//Plus complexe</span>
<span style="color: #000080;">$nombre</span><span style="color: #8000FF;">=</span><span style="color: #FF8000;">3</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$resultat</span> <span style="color: #8000FF;">=</span><span style="color: #000080;">$nombre</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">6</span><span style="color: #8000FF;">;</span><span style="color: #008000; font-style: italic;">//$resultat prend la valeur 18</span>
<span style="color: #008000; font-style: italic;">//Le modulo</span>
<span style="color: #000080;">$resultat</span> <span style="color: #8000FF;">=</span> <span style="color: #FF8000;">9</span><span style="color: #8000FF;">%</span><span style="color:#800080;">4</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//$resultat prend comme valeur le reste de la division, c'est ? dire 1 dans ce cas pr?cis</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Les conditions</h3><br />
<br />
 <h4 class="formatter-title">Les symboles</h4> <br />
<span class="warning"><br />
Avant de commencer, les symboles ? connaitre : <br />
== : Est ?gal ?;  > : Est sup?rieur ?; < : Est inf?rieur ?; >= : Est sup?rieur ou ?gal ?; <= : Est inf?rieur ou ?gal ?; != : Est diff?rent de;<br />
</span><br />
<br />
<span class="notice">Notez que dans les conditions on utilisera toujours la double ?galit?.</span><br />
<br />
 <h4 class="formatter-title">if...else</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #008000; font-style: italic;">//cas des entiers</span>
<span style="color: #000080;">$age</span><span style="color: #8000FF;">=</span><span style="color: #FF8000;">25</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">if</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$age</span> <span style="color: #8000FF;"><</span><span style="color: #FF8000;">18</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'vous ?tes mineur'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #0000FF; font-weight: bold;">elseif</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$age</span><span style="color: #8000FF;">==</span><span style="color: #FF8000;">18</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Bravo!!'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #0000FF; font-weight: bold;">else</span><span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'vous ?tes majeurs'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">//cas des chaines de caract?res</span>
<span style="color: #0000FF; font-weight: bold;">if</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$nom</span><span style="color: #8000FF;">==</span><span style="color: #808080;">"pearson"</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Bienvenue administrateur!!'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #0000FF; font-weight: bold;">else</span><span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Bienvenue visiteur'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">//cas des bool?ens</span>
<span style="color: #000080;">$majeur</span><span style="color: #8000FF;">=</span><span style="">false</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">if</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$majeur</span><span style="color: #8000FF;">==</span><span style="">true</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Autorisation accord?e'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #0000FF; font-weight: bold;">else</span><span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Vous n\'?tes pas autoris?s'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Conditions multiples</span></strong><br />
<br />
On souhaite poser plusieurs conditions ? la fois. Les principaux mots cl?s ? connaitre sont :<br />
<strong>AND </strong>: symbole ?quivalent( && ); signification (et)<br />
<strong>OR</strong> : symbole ?quivalent( || ); signification (ou)<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//AND</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$age</span> <span style="color: #8000FF;">>=</span><span style="color: #FF8000;">30</span> <span style="color: #8000FF;">&&</span> <span style="color: #000080;">$sexe</span> <span style="color: #8000FF;">==</span> <span style="color: #808080;">"homme"</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">"Bonjour Monsieur"</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">//OR</span>
<span style="color: #0000FF; font-weight: bold;">if</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$pays</span><span style="color: #8000FF;">==</span><span style="color: #808080;">"France"</span> <span style="color: #8000FF;">||</span> <span style="color: #000080;">$pays</span><span style="color: #8000FF;">==</span><span style="color: #808080;">"Espagne"</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">"salut Europ?en"</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">switch</h4> <br />
<br />
switch est une alternative ? if...else pour ?viter une structure longue et r?p?titive.<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$note</span> <span style="color: #8000FF;">=</span> <span style="color: #FF8000;">10</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">switch</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$note</span><span style="color: #8000FF;">&#41;</span> <span style="color: #008000; font-style: italic;">// on indique sur quelle variable on travaille</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">case</span> <span style="color: #FF8000;">0</span><span style="color: #8000FF;">:</span> <span style="color: #008000; font-style: italic;">// dans le cas o? $note vaut 0</span>
        <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">"Tu es vraiment null!!!"</span><span style="color: #8000FF;">;</span>
    <span style="color: #0000FF; font-weight: bold;">break</span><span style="color: #8000FF;">;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">case</span> <span style="color: #FF8000;">10</span><span style="color: #8000FF;">:</span> 
        <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">"Passable"</span><span style="color: #8000FF;">;</span>
    <span style="color: #0000FF; font-weight: bold;">break</span><span style="color: #8000FF;">;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">case</span> <span style="color: #FF8000;">20</span><span style="color: #8000FF;">:</span>
        <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">"Excellent travail!"</span><span style="color: #8000FF;">;</span>
    <span style="color: #0000FF; font-weight: bold;">break</span><span style="color: #8000FF;">;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">default</span><span style="color: #8000FF;">:</span>
        <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">"D?sol?, je n'ai pas de mention ? afficher pour cette note"</span><span style="color: #8000FF;">;</span><span style="color: #008000; font-style: italic;">//message par d?faut</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Les ternaires : conditions condens?es</h4> <br />
<br />
Dans l'exemple ci-dessous, si l'age est sup?rieur ? 18 alors la variable $majeur prend la valeur true.<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$age</span> <span style="color: #8000FF;">=</span> <span style="color: #FF8000;">24</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #000080;">$majeur</span> <span style="color: #8000FF;">=</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$age</span> <span style="color: #8000FF;">>=</span> <span style="color: #FF8000;">18</span><span style="color: #8000FF;">&#41;</span> ? <span style="">true</span> <span style="color: #8000FF;">:</span> <span style="">false</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Boucle while</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Ecrire le num?ro de ligne 100 fois</span>
<span style="color: #000080;">$nombre_de_lignes</span> <span style="color: #8000FF;">=</span> <span style="color: #FF8000;">1</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">while</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$nombre_de_lignes</span> <span style="color: #8000FF;"><=</span> <span style="color: #FF8000;">100</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Ligne numero '</span><span style="color: #8000FF;">.</span><span style="color: #000080;">$nombre_de_lignes</span><span style="color: #8000FF;">.</span><span style="color: #808080;">'<br />'</span><span style="color: #8000FF;">;</span>
    <span style="color: #008000; font-style: italic;">//Le compteur de lignes est incr?ment? ? chaque fois</span>
    <span style="color: #000080;">$nombre_de_lignes</span><span style="color: #8000FF;">++;</span> <span style="color: #008000; font-style: italic;">// $nombre_de_lignes = $nombre_de_lignes + 1</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<span class="notice"><br />
La boucle pose la condition : <strong>TANT QUE</strong> $nombre_de_lignes est inf?rieur ou ?gal ? 100.<br />
</span><br />
<br />
 <h4 class="formatter-title">Boucle for</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$nombre_de_lignes</span> <span style="color: #8000FF;">=</span> <span style="color: #FF8000;">1</span><span style="color: #8000FF;">;</span> <span style="color: #000080;">$nombre_de_lignes</span> <span style="color: #8000FF;"><=</span> <span style="color: #FF8000;">100</span><span style="color: #8000FF;">;</span> <span style="color: #000080;">$nombre_de_lignes</span><span style="color: #8000FF;">++</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Ligne n?'</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$nombre_de_lignes</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'<br />'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><br />
3 ?l?ments interviennent dans la boucle for. Le premier sert ? <strong>l'initialisation</strong>. Le second, c'est la <strong>condition</strong>. Enfin, le troisi?me c'est l'<strong>incr?mentation</strong>.<br />
</span><br />
<br />
<h3 class="formatter-title">Les tableaux</h3><br />
<br />
 <h4 class="formatter-title">Tableaux num?rot?s</h4> <br />
<br />
<span class="warning"> La fonction array permet de cr?er un array (tableau). La num?rotation des ?l?ments d'un tableau commence par z?ro.</span><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Methode 1</span>
<span style="color: #000080;">$prenoms</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a> <span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Fran?ois'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Michel'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Nicole'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'V?ronique'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Beno?t'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//M?thode 2 : Cr?ation manuelle</span>
<span style="color: #000080;">$prenoms</span><span style="color: #8000FF;">&#91;</span><span style="color: #FF8000;">0</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'Fran?ois'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$prenoms</span><span style="color: #8000FF;">&#91;</span><span style="color: #FF8000;">1</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'Michel'</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//M?thode 3 : PHP affecte automatiquement les num?ros de case</span>
<span style="color: #000080;">$prenoms</span><span style="color: #8000FF;">&#91;</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'Fran?ois'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// Cr?era $prenoms[0]</span>
<span style="color: #000080;">$prenoms</span><span style="color: #8000FF;">&#91;</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'Michel'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// Cr?era $prenoms[1]</span>
<span style="color: #008000; font-style: italic;">//Afficher un tableau num?rot?</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$prenoms</span><span style="color: #8000FF;">&#91;</span><span style="color: #FF8000;">1</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Tableaux associatifs</h4> <br />
<br />
Dans le cas d'un tableau associatif, les cases ne sont pas num?rot?es mais plut?t ?tiquet?es.<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">// On cr?e notre array $coordonnees</span>
<span style="color: #008000; font-style: italic;">//M?thode 1</span>
<span style="color: #000080;">$coordonnees</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a> <span style="color: #8000FF;">&#40;</span>
    <span style="color: #808080;">'prenom'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Fran?ois'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'nom'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Dupont'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'adresse'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'3 Rue du Paradis'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'ville'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Marseille'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//M?thode 2</span>
<span style="color: #000080;">$coordonnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prenom'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'Fran?ois'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$coordonnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'nom'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'Dupont'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$coordonnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'adresse'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'3 Rue du Paradis'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$coordonnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'ville'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'Marseille'</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//Afficher un tableau associatif</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$coordonnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'ville'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Parcourir un tableau</h4> <br />
<br />
Trois moyens d'explorer un tableau : for, foreach, print_r.<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">// On cr?e notre array $prenoms</span>
<span style="color: #000080;">$prenoms</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a> <span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Fran?ois'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Michel'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Nicole'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'V?ronique'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Beno?t'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// Boucle for pour tout afficher :</span>
<span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$numero</span> <span style="color: #8000FF;">=</span> <span style="color: #FF8000;">0</span><span style="color: #8000FF;">;</span> <span style="color: #000080;">$numero</span> <span style="color: #8000FF;"><</span> <span style="color: #FF8000;">5</span><span style="color: #8000FF;">;</span> <span style="color: #000080;">$numero</span><span style="color: #8000FF;">++</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$prenoms</span><span style="color: #8000FF;">&#91;</span><span style="color: #000080;">$numero</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'<br />'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// affichera $prenoms[0], $prenoms[1] etc.</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">//Boucle foreach</span>
<span style="color: #0000FF; font-weight: bold;">foreach</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$prenoms</span> <span style="color: #0000FF; font-weight: bold;">as</span> <span style="color: #000080;">$element</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$element</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'<br />'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// affichera $prenoms[0], $prenoms[1] etc.</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">//affiche rapidement un tableau avec print_r</span>
<span style="color: #008000; font-style: italic;">//utile pour le d?bogage lors de la conception d'un site</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'<pre>'</span><span style="color: #8000FF;">;</span>
<a href="http://www.php.net/print_r"><span style="color: #0000FF; font-weight: bold;">print_r</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$coordonnees</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'</pre>'</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success">L'avantage de foreach, c'est qu'il permet de parcourir ?galement les tableaux associatifs.</span><br />
<br />
<span style="color:blue;"><strong>Exemple:</strong></span><br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$coordonnees</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a> <span style="color: #8000FF;">&#40;</span>
    <span style="color: #808080;">'prenom'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Fran?ois'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'nom'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Dupont'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'adresse'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'3 Rue du Paradis'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'ville'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Marseille'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">foreach</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$coordonnees</span> <span style="color: #0000FF; font-weight: bold;">as</span> <span style="color: #000080;">$element</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$element</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'<br />'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">//On peut aussi r?cup?rer la cl? de l'?l?ment</span>
<span style="color: #0000FF; font-weight: bold;">foreach</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$coordonnees</span> <span style="color: #0000FF; font-weight: bold;">as</span> <span style="color: #000080;">$cle</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$element</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'['</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$cle</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'] vaut '</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$element</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'<br />'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span> 
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Rechercher dans un tableau</h4> <br />
<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span> 
<span style="color: #008000; font-style: italic;">//********************************************************************</span>
<span style="color: #008000; font-style: italic;">//V?rifier si une cl? existe dans l'array : array_key_exists</span>
<span style="color: #008000; font-style: italic;">//********************************************************************</span>
<span style="color: #000080;">$coordonnees</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a> <span style="color: #8000FF;">&#40;</span>
    <span style="color: #808080;">'prenom'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Fran?ois'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'nom'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Dupont'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'adresse'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'3 Rue du Paradis'</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'ville'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Marseille'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/array_key_exists"><span style="color: #0000FF; font-weight: bold;">array_key_exists</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'nom'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$coordonnees</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'La cl? "nom" se trouve dans les coordonn?es !'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">//********************************************************************</span>
<span style="color: #008000; font-style: italic;">//V?rifier si une valeur existe dans l'array : in_array</span>
<span style="color: #008000; font-style: italic;">//********************************************************************</span>
<span style="color: #000080;">$fruits</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a> <span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Banane'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Pomme'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Poire'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Cerise'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Fraise'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Framboise'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/in_array"><span style="color: #0000FF; font-weight: bold;">in_array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Myrtille'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$fruits</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'La valeur "Myrtille" se trouve dans les fruits !'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">//********************************************************************</span>
<span style="color: #008000; font-style: italic;">//R?cup?rer la cl? d'une valeur dans l'array : array_search</span>
<span style="color: #008000; font-style: italic;">//********************************************************************</span>
<span style="color: #000080;">$position</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array_search"><span style="color: #0000FF; font-weight: bold;">array_search</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Fraise'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$fruits</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'"Fraise" se trouve en position '</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$position</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'<br />'</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<span class="warning"><br />
N'oubliez pas qu'un array num?rot? commence ? 0 !  ? Fraise ? se trouve donc en position 4.</span><br />
<br />
[page]Transmettre des donn?es de page en page[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Envoyer des donn?es dans l'URL</h3><br />
<br />
 <h4 class="formatter-title">Envoie des donn?es</h4> <br />
Soit deux pages <strong>index.php</strong> et <strong>bonjour.php</strong>.  La page index.php envoie les variables nom et pr?nom ? la page bonjour.php. Cette derni?re les r?cup?re et affiche bonjour ? la personne.<br />
<br />
<strong>Il suffit de cr?er un lien avec des param?tres qui m?ne vers la page bonjour de la forme suivante :<br />
page.php?param1=valeur1?m2=valeur2?m3=valeur3?m4=valeur4?</strong><br />
<br />
<span class="notice">Il n'est pas conseill? de d?passer les 256 caract?res</span><br />
<br />
Ouvrez index.php et ins?rez-y par exemple le code suivant :<br />
<br />
<span class="formatter-code">Code HTML :</span><div class="code"><pre style="display:inline;"><pre class="html" style="font-family:monospace;"><span style="color: #009900;"><<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"bonjour.php?nom=Dupont&prenom=Jean"</span>></span>Dis-moi bonjour !<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>></span></pre></pre></div><br />
<br />
 <h4 class="formatter-title">R?cup?ration des donn?es</h4> <br />
<br />
<span class="warning">La commande <strong>$_GET</strong> permet de r?cup?rer les donn?es. On va d'abord tester l?existence des param?tres avant de les r?cup?rer au cas o? le visiteur aurait trafiquer l'URL</span><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//La commande isset teste l'existence des param?tres</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #0000FF; font-weight: bold;">isset</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prenom'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span> AND <a href="http://www.php.net/isset"><span style="color: #0000FF; font-weight: bold;">isset</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'nom'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span> <span style="color: #008000; font-style: italic;">// On a le nom et le pr?nom</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Bonjour '</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prenom'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">' '</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'nom'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">' !'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #0000FF; font-weight: bold;">else</span> <span style="color: #008000; font-style: italic;">// Il manque des param?tres, on avertit le visiteur</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Il faut renseigner un nom et un pr?nom !'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Envoyer des donn?es via un formulaire</h3><br />
<br />
 <h4 class="formatter-title">Base du formulaire</h4> <br />
<br />
<span class="formatter-code">Code HTML :</span><div class="code"><pre style="display:inline;"><pre class="html" style="font-family:monospace;">&nbsp;
<span style="color: #009900;"><<a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post"</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"page_cible.php"</span>></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>></span>
    On ins?rera ici les ?l?ments de notre formulaire.
<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>></span>
<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a>></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Les donn?es seront r?cup?r?es gr?ce ? la fonction $_POST.</span><br />
<br />
 <h4 class="formatter-title">Les ?l?ments du formulaire</h4> <br />
<br />
<span class="formatter-code">Code HTML :</span><div class="code"><pre style="display:inline;"><pre class="html" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;"><!--//**********************************************************************************************</span>
<span style="color: #808080; font-style: italic;">//champ de texte</span>
<span style="color: #808080; font-style: italic;">//name(obligatoire)  : La valeur du champ r?cup?r?e via $_POST['pseudo']</span>
<span style="color: #808080; font-style: italic;">//value(facultatif) : valeur par d?faut du champ</span>
<span style="color: #808080; font-style: italic;">//**********************************************************************************************--></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text"</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"pseudo"</span>  <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"pearson"</span><span style="color: #66cc66;">/</span>></span>
<span style="color: #808080; font-style: italic;"><!--//**********************************************************************************************</span>
<span style="color: #808080; font-style: italic;">//Les grandes zones de texte</span>
<span style="color: #808080; font-style: italic;">//R?cup?ration du contenu via $_POST['message']</span>
<span style="color: #808080; font-style: italic;">//**********************************************************************************************--></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/textarea.html"><span style="color: #000000; font-weight: bold;">textarea</span></a> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"message"</span> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"8"</span> <span style="color: #000066;">cols</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"45"</span>></span>
Votre message ici.
<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/textarea.html"><span style="color: #000000; font-weight: bold;">textarea</span></a>></span>
<span style="color: #808080; font-style: italic;"><!--//**********************************************************************************************</span>
<span style="color: #808080; font-style: italic;">//La liste d?roulante</span>
<span style="color: #808080; font-style: italic;">//Une variable $_POST['choix'] contenant le choix de l'utilisateur est cr??. </span>
<span style="color: #808080; font-style: italic;">//S'il a choisi ? Choix 3 ?, la variable $_POST['choix'] sera ?gale au value correspondant, c'est-?-dire choix3.</span>
<span style="color: #808080; font-style: italic;">//**********************************************************************************************--></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/select.html"><span style="color: #000000; font-weight: bold;">select</span></a> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"choix"</span>></span>
    <span style="color: #009900;"><<a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"choix1"</span>></span>Choix 1<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>></span>
    <span style="color: #009900;"><<a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"choix2"</span> <span style="color: #000066;">selected</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"selected"</span>></span>Choix 2<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>></span>//choix par d?faut gr?ce ? l'option selected
    <span style="color: #009900;"><<a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"choix3"</span>></span>Choix 3<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>></span>
<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/select.html"><span style="color: #000000; font-weight: bold;">select</span></a>></span>
<span style="color: #808080; font-style: italic;"><!--//**********************************************************************************************</span>
<span style="color: #808080; font-style: italic;">//Case ? cocher</span>
<span style="color: #808080; font-style: italic;">//la variable $_POST['case'] est cr??e dans la page cible. Si elle est coch?e, sa valeur est ?gale "on"; sinon elle n'existe pas</span>
<span style="color: #808080; font-style: italic;">//Pour cocher une case par d?faut : mettre l'attribut checked="checked"</span>
<span style="color: #808080; font-style: italic;">// Faire un test avec isset($_POST['case']) pour v?rifier si la case a ?t? coch?e ou non.</span>
<span style="color: #808080; font-style: italic;">**********************************************************************************************--></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"checkbox"</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"case"</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"case"</span> <span style="color: #66cc66;">/</span>></span> <span style="color: #009900;"><<a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"case"</span>></span>case<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a>></span> 
<span style="color: #808080; font-style: italic;"><!--**********************************************************************************************</span>
<span style="color: #808080; font-style: italic;">//Bouton d?options</span>
<span style="color: #808080; font-style: italic;">//Pour pr?-cocher une case par d?faut : mettre l'attribut checked="checked"</span>
<span style="color: #808080; font-style: italic;">//Variable cr??e $_POST['frites']. Elle aura la valeur du bouton d'option choisi par le visiteur, issue de l'attribut value. </span>
<span style="color: #808080; font-style: italic;">//Si on aime les frites, alors on aura $_POST['frites'] = 'oui'.</span>
<span style="color: #808080; font-style: italic;">//**********************************************************************************************--></span>
Aimez-vous les frites ?
<span style="color: #009900;"><<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"radio"</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"frites"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"oui"</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"oui"</span> <span style="color: #000066;">checked</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"checked"</span> <span style="color: #66cc66;">/</span>></span> <span style="color: #009900;"><<a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"oui"</span>></span>Oui<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a>></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"radio"</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"frites"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"non"</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"non"</span> <span style="color: #66cc66;">/</span>></span> <span style="color: #009900;"><<a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"non"</span>></span>Non<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a>></span>
<span style="color: #808080; font-style: italic;"><!--**********************************************************************************************</span>
<span style="color: #808080; font-style: italic;">//Les champs cach?s</span>
<span style="color: #808080; font-style: italic;">//Le champ n'est pas affich? aux visiteurs mais il est envoy? ? la page cible lors de la validation du formulaire</span>
<span style="color: #808080; font-style: italic;">//**********************************************************************************************--></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"hidden"</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"pseudo"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"pearson"</span> <span style="color: #66cc66;">/</span>></span>
<span style="color: #808080; font-style: italic;"><!--**********************************************************************************************</span>
<span style="color: #808080; font-style: italic;">//Bouton d?envois du formulaire</span>
<span style="color: #808080; font-style: italic;">//**********************************************************************************************--></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"submit"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"Valider"</span> <span style="color: #66cc66;">/</span>></span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->

<div class="highlight_3d" style="width:95%; height:370px;">
<b>champ de texte</b>
<input type="text" name="pseudo"  value="pearson"/>
<br/><br/>
<b>Les grandes zones de texte</b>
<textarea name="message" rows="8" cols="45">
Votre message ici.
</textarea>
<br/><br/>
<b>La liste d?roulante</b>
<select name="choix">
    <option value="choix1">France</option>
    <option value="choix2" selected="selected">Espagne</option>//choix par d?faut gr?ce ? l'option selected
    <option value="choix3">Italie</option>
</select>
<br/><br/>
<b>Case ? cocher</b><br/>
<input type="checkbox" name="frite" id="frite" /> <label for="frite">Frites</label> <br/>
<input type="checkbox" name="choux" id="choux" checked="checked" /> <label for="choux">Choux</label> <br/>
<input type="checkbox" name="banane" id="banane"  /> <label for="banane">Banane</label> 
<br/><br/>
<b>Bouton d'options</b>
Aimez-vous les frites ?
<input type="radio" name="frites" value="oui" id="oui" checked="checked" /> <label for="oui">Oui</label>
<input type="radio" name="frites" value="non" id="non" /> <label for="non">Non</label>
<br/><br/>
<b>Bouton valider</b>
<input type="submit" value="Valider" />
</div>

<!-- END HTML --><br />
<br />
<br />
 <h4 class="formatter-title">R?cup?ration des donn?es</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span> 
<span style="color: #008000; font-style: italic;">//?chappement des balises html</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <a href="http://www.php.net/htmlspecialchars"><span style="color: #0000FF; font-weight: bold;">htmlspecialchars</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_POST</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prenom'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> 
<span style="color: #008000; font-style: italic;">//suppression des balises html</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <a href="http://www.php.net/strip_tags"><span style="color: #0000FF; font-weight: bold;">strip_tags</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_POST</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prenom'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Notez l'utilisation de la fonction <strong>htmlspecialchars</strong>. Elle permet d'?chapper les balises HTML ins?r?es par le visiteurs prot?geant ainsi votre site d'?ventuelles attaques. Les balises HTML seront affich?es mais non ex?cut?es.<br />
</span><br />
<br />
<span class="success"><br />
Si vous pr?f?rez retirer les balises HTML que le visiteur a tent? d'envoyer plut?t que de les afficher, utilisez la fonction <strong>strip_tags</strong>.<br />
</span><br />
<br />
<h3 class="formatter-title">Envoyer un fichier </h3><br />
<br />
 <h4 class="formatter-title">Formulaire d'envois</h4> <br />
<br />
<span class="notice">Si le formulaire propose aux visiteurs d'envoyer un fichier, il faut ajouter l'attribut enctype="multipart/form-data" ? la balise <form>.</span><br />
<br />
<span class="formatter-code">Code HTML :</span><div class="code"><pre style="display:inline;"><pre class="html" style="font-family:monospace;">&nbsp;
<span style="color: #009900;"><<a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"page_cible.php"</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post"</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"multipart/form-data"</span>></span>
        <span style="color: #009900;"><<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>></span>
                Formulaire d'envoi de fichier :<span style="color: #009900;"><<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>></span>
                <span style="color: #009900;"><<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"file"</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"monfichier"</span> <span style="color: #66cc66;">/</span>><<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>></span>
                <span style="color: #009900;"><<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"submit"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"Envoyer le fichier"</span> <span style="color: #66cc66;">/</span>></span>
        <span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>></span>
<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a>></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Traitement de l'envoi</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">// Testons si le fichier a bien ?t? envoy? et s'il n'y a pas d'erreur</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #0000FF; font-weight: bold;">isset</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_FILES</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'monfichier'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span> AND <span style="color: #000080;">$_FILES</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'monfichier'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'error'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">==</span> <span style="color: #FF8000;">0</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
        <span style="color: #008000; font-style: italic;">// Testons si le fichier n'est pas trop gros</span>
        <span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_FILES</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'monfichier'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'size'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;"><=</span> <span style="color: #FF8000;">1000000</span><span style="color: #8000FF;">&#41;</span> <span style="color: #008000; font-style: italic;">// en octet; 1 MO = 1000 000 octets</span>
        <span style="color: #8000FF;">&#123;</span>
                <span style="color: #008000; font-style: italic;">// Testons si l'extension est autoris?e</span>
                <span style="color: #000080;">$infosfichier</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/pathinfo"><span style="color: #0000FF; font-weight: bold;">pathinfo</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_FILES</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'monfichier'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'name'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
                <span style="color: #000080;">$extension_upload</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$infosfichier</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'extension'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span>
                <span style="color: #000080;">$extensions_autorisees</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'jpg'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'jpeg'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'gif'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'png'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
                <span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/in_array"><span style="color: #0000FF; font-weight: bold;">in_array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$extension_upload</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$extensions_autorisees</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>
                <span style="color: #8000FF;">&#123;</span>
                        <span style="color: #008000; font-style: italic;">// On peut valider le fichier et le stocker d?finitivement</span>
                        <a href="http://www.php.net/move_uploaded_file"><span style="color: #0000FF; font-weight: bold;">move_uploaded_file</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_FILES</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'monfichier'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'tmp_name'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'uploads/'</span> <span style="color: #8000FF;">.</span> <a href="http://www.php.net/basename"><span style="color: #0000FF; font-weight: bold;">basename</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_FILES</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'monfichier'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'name'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
                        <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">"L'envoi a bien ?t? effectu? !"</span><span style="color: #8000FF;">;</span>
                <span style="color: #8000FF;">&#125;</span>
        <span style="color: #8000FF;">&#125;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><br />
Le fichier est plac? dans le dossier uploads. V?rifiez que le dossier upload existe sur le serveur et qu'il a les droits d'?criture (CHMOD 733)<br />
</span><br />
<br />
<span class="error"><br />
Ce script est encore ? am?liorer.  Par exemple, si le nom du fichier contient des espaces ou des accents, ?a posera un probl?me une fois envoy? sur le Web. D'autre part, si quelqu'un envoie un fichier qui a le m?me nom que celui d'une autre personne, l'ancien sera ?cras? !<br />
La solution consiste en g?n?ral ? ? choisir ? nous-m?mes le nom du fichier stock? sur le serveur plut?t que de se servir du nom d'origine. Vous pouvez faire un compteur qui s'incr?mente : 1.png, 2.png, 3.jpg, etc.<br />
</span><br />
<br />
<h3 class="formatter-title">Les variables superglobales, sessions et cookie</h3><br />
<br />
Les variables superglobales sont accessibles sur toutes les pages de votre site.<br />
<br />
 <h4 class="formatter-title">Les sessions</h4> <br />
<br />
Pour chaque visiteur, un num?ro de session unique est cr?? automatiquement par PHP. PHP transmet cet ID de page en page en utilisant g?n?ralement un cookie.<br />
<br />
<ul class="formatter-ul">
<li class="formatter-li"><strong>session_start()</strong> : d?marre le syst?me de sessions.
</li><li class="formatter-li"><strong>session_destroy()</strong> : ferme la session du visiteur. Cette fonction est automatiquement appel?e lorsque le visiteur ne charge plus de page de votre site pendant plusieurs minutes (c'est le timeout), mais elle peut ?tre utilis?e pour la d?connexion manuelle du visiteur.<br />
</li></ul><br />
<br />
<span class="error"><br />
Il faut appeler session_start() sur chacune de vos pages AVANT d'?crire le moindre code HTML (avant m?me la balise <!DOCTYPE> ). Si vous oubliez de lancer session_start(), vous ne pourrez pas acc?der aux variables superglobales $_SESSION<br />
</span><br />
<br />
<strong><span style="color:blue;">Exemple</span></strong><br />
<span class="formatter-code">Code HTML :</span><div class="code"><pre style="display:inline;"><pre class="html" style="font-family:monospace;">&nbsp;
<span style="color: #009900;"><?php</span>
<span style="color: #009900;"><span style="color: #66cc66;">//</span> On d?marre la session AVANT d<span style="color: #ff0000;">'?crire du code HTML</span>
<span style="color: #009900;">session_start();</span>
&nbsp;
<span style="color: #009900;">// On s'</span>amuse ? cr?er quelques variables de session dans $_SESSION</span>
<span style="color: #009900;">$_SESSION<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'prenom'</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Jean'</span>;</span>
<span style="color: #009900;">$_SESSION<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'nom'</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Dupont'</span>;</span>
<span style="color: #009900;">$_SESSION<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'age'</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">24</span>;</span>
<span style="color: #009900;">?></span>
&nbsp;
<span style="color: #00bbdd;"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"></span>
<span style="color: #009900;"><<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"http://www.w3.org/1999/xhtml"</span> xml:<span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"fr"</span> ></span>
   <span style="color: #009900;"><<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>></span>
       <span style="color: #009900;"><<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>></span>Titre de ma page<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>></span>
    <span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>></span>
    <span style="color: #009900;"><<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>></span>
    <span style="color: #009900;"><<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>></span>
        Salut <span style="color: #009900;"><?php echo $_SESSION<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'prenom'</span><span style="color: #66cc66;">&#93;</span>; ?></span> !<span style="color: #009900;"><<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>></span>
        Tu es ? l'accueil de mon site (index.php). Tu veux aller sur une autre page ?
    <span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>></span>
    <span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>></span>
<span style="color: #009900;"><<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Les cookies</h4> <br />
<br />
Un cookie, c'est un petit fichier que l'on enregistre sur l'ordinateur du visiteur. Ce fichier contient du texte permettant de ? retenir ? des informations sur le visiteur.<br />
<br />
<span style="color:blue;"><strong>Ecrire un cookie</strong></span><br />
<br />
On utilise la fonction PHP setcookie en lui donnant, en g?n?ral trois param?tres, dans l'ordre suivant :<br />
<br />
    le nom du cookie (ex. : pseudo) ;<br />
    la valeur du cookie (ex. : M@teo21) ;<br />
    la date d'expiration du cookie, sous forme de timestamp (ex. : 1090521508).<br />
<br />
<span class="success">Si vous voulez supprimer le cookie dans un an, il vous faudra donc ?crire : time() + 365*24*3600. Cela veut dire : timestamp actuel $+$ nombre de secondes dans une ann?e.</span><br />
<br />
La commande est la suivante pour cr?er un cookie:<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span> <a href="http://www.php.net/setcookie"><span style="color: #0000FF; font-weight: bold;">setcookie</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'pseudo'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'M@teo21'</span><span style="color: #8000FF;">,</span> <a href="http://www.php.net/time"><span style="color: #0000FF; font-weight: bold;">time</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span> <span style="color: #8000FF;">+</span> <span style="color: #FF8000;">365</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">24</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">3600</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> 
<span style="color: #008000; font-style: italic;">//S?curiser son cookie avec le mode httpOnly; le dernier true active le httpOnly</span>
<a href="http://www.php.net/setcookie"><span style="color: #0000FF; font-weight: bold;">setcookie</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'pseudo'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'M@teo21'</span><span style="color: #8000FF;">,</span> <a href="http://www.php.net/time"><span style="color: #0000FF; font-weight: bold;">time</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span> <span style="color: #8000FF;">+</span> <span style="color: #FF8000;">365</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">24</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">3600</span><span style="color: #8000FF;">,</span> <span style="">null</span><span style="color: #8000FF;">,</span> <span style="">null</span><span style="color: #8000FF;">,</span> <span style="">false</span><span style="color: #8000FF;">,</span> <span style="">true</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="error"><br />
 Comme pour session_start, setcookie ne marche QUE si vous l'appelez avant tout code HTML (donc avant la balise <!DOCTYPE&gt<img src="https://www.sthda.com/french/french/images/smileys/wink.png" alt=";)" class="smiley" />.<br />
</span><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<a href="http://www.php.net/setcookie"><span style="color: #0000FF; font-weight: bold;">setcookie</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'pseudo'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'M@teo21'</span><span style="color: #8000FF;">,</span> <a href="http://www.php.net/time"><span style="color: #0000FF; font-weight: bold;">time</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span> <span style="color: #8000FF;">+</span> <span style="color: #FF8000;">365</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">24</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">3600</span><span style="color: #8000FF;">,</span> <span style="">null</span><span style="color: #8000FF;">,</span> <span style="">null</span><span style="color: #8000FF;">,</span> <span style="">false</span><span style="color: #8000FF;">,</span> <span style="">true</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// On ?crit un cookie</span>
<a href="http://www.php.net/setcookie"><span style="color: #0000FF; font-weight: bold;">setcookie</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'pays'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'France'</span><span style="color: #8000FF;">,</span> <a href="http://www.php.net/time"><span style="color: #0000FF; font-weight: bold;">time</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span> <span style="color: #8000FF;">+</span> <span style="color: #FF8000;">365</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">24</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">3600</span><span style="color: #8000FF;">,</span> <span style="">null</span><span style="color: #8000FF;">,</span> <span style="">null</span><span style="color: #8000FF;">,</span> <span style="">false</span><span style="color: #8000FF;">,</span> <span style="">true</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// On ?crit un autre cookie...</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// Et SEULEMENT MAINTENANT, on peut commencer ? ?crire du code html</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
   <head>
       <title>Ma super page PHP</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
&nbsp;
  etc.
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Afficher un cookie</span></strong><br />
<br />
<span class="notice"><br />
 Il faut faire un isset pour v?rifier si le cookie existe ou non.<br />
</span><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<p>
    H? ! Je me souviens de toi !<br />
    Tu t'appelles <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$_COOKIE</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'pseudo'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span> et tu viens de <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$_COOKIE</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'pays'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span> c'est bien ?a ?
</p>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Les cookies viennent du visiteur. Il peut les avoir modifi?s, donc soyez prudents et n'ayez pas une confiance aveugle en leur contenu !<br />
</span><br />
<br />
<strong><span style="color:blue;">Modifier un cookie existant</span></strong><br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<a href="http://www.php.net/setcookie"><span style="color: #0000FF; font-weight: bold;">setcookie</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'pays'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Chine'</span><span style="color: #8000FF;">,</span> <a href="http://www.php.net/time"><span style="color: #0000FF; font-weight: bold;">time</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span> <span style="color: #8000FF;">+</span> <span style="color: #FF8000;">365</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">24</span><span style="color: #8000FF;">*</span><span style="color: #FF8000;">3600</span><span style="color: #8000FF;">,</span> <span style="">null</span><span style="color: #8000FF;">,</span> <span style="">null</span><span style="color: #8000FF;">,</span> <span style="">false</span><span style="color: #8000FF;">,</span> <span style="">true</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<br />
[page]Lire et ?crire dans un fichier[/page]<br />
<br />
Pour ?crire dans un dossier PHP doit avoir les droits. Gr?ce ? votre logicel FTP (ie:Filezilla) vous pouvez changer les permissions des fichiers et dossiers.<br />
<br />
<strong><span style="color:blue;">Pour lire ou ?crire dans un fichier, il faut d'abord l'ouvrir:</span></strong><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">// 1 : on ouvre le fichier</span>
<span style="color: #000080;">$monfichier</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/fopen"><span style="color: #0000FF; font-weight: bold;">fopen</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'compteur.txt'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'r+'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
&nbsp;
<span style="color: #000080;">$pages_vues</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/fgets"><span style="color: #0000FF; font-weight: bold;">fgets</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$monfichier</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// On lit la premi?re ligne (nombre de pages vues)</span>
<span style="color: #000080;">$pages_vues</span><span style="color: #8000FF;">++;</span> <span style="color: #008000; font-style: italic;">// On augmente de 1 ce nombre de pages vues</span>
<a href="http://www.php.net/fseek"><span style="color: #0000FF; font-weight: bold;">fseek</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$monfichier</span><span style="color: #8000FF;">,</span> <span style="color: #FF8000;">0</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// On remet le curseur au d?but du fichier</span>
<a href="http://www.php.net/fputs"><span style="color: #0000FF; font-weight: bold;">fputs</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$monfichier</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$pages_vues</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// On ?crit le nouveau nombre de pages vues</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// 3 : quand on a fini de l'utiliser, on ferme le fichier</span>
<a href="http://www.php.net/fclose"><span style="color: #0000FF; font-weight: bold;">fclose</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$monfichier</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Plusieurs modes d'ouverture existent :<br />
<strong>r </strong>: Ouvre le fichier en lecture seule. Cela signifie que vous pourrez seulement lire le fichier.<br />
<strong>r+</strong>:Ouvre le fichier en lecture et ?criture.<br />
<strong>a </strong>: Ouvre le fichier en ?criture seule. Si le fichier n'existe pas, il est automatiquement cr??.<br />
<strong>a+</strong>:Ouvre le fichier en lecture et ?criture. Si le fichier & n'existe pas, il est cr?? automatiquement. Attention : le r?pertoire doit avoir un CHMOD ? 777 dans ce cas ! ? noter que si le fichier existe d?j?, le texte sera rajout? ? la fin.<br />
</span><br />
<br />
<br />
<br />
[page]Base de donn?es[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Cr?ation d'une table avec phpMyAdmin</h3><br />
<br />
Les diff?rentes colonnes de la table sont appel?es "champ". <br />
<br />
<strong><span style="color:blue;">Les param?tres des champs sont :</span></strong><br />
    <strong>Champ </strong>: permet de d?finir le nom du champ;<br />
    <strong>Type </strong>: le type de donn?es que va stocker le champ (nombre entier, texte, date? ) ;<br />
    <strong>Taille/Valeurs</strong> : permet d'indiquer la taille maximale du champ, utile pour le type VARCHAR notamment, afin de limiter le nombre de caract?res autoris?s ;<br />
    <strong>Index</strong> : active l'indexation du champ. Ceci signifie que votre champ sera adapt? aux recherches. Le plus souvent, on utilise l'index PRIMARY sur les champs de type id ;<br />
    <strong>AUTO_INCREMENT</strong> : permet au champ de s'incr?menter tout seul ? chaque nouvelle entr?e. On l'utilise fr?quemment sur les champs de type id.<br />
<br />
<strong><span style="color:blue;">Plusieurs types de champs MySQL existent :</span></strong><br />
<br />
    <strong>INT</strong> : nombre entier ;<br />
    <strong>VARCHAR</strong> : texte court (entre 1 et 255 caract?res) ;<br />
    <strong>TEXT</strong> : long texte (on peut y stocker un roman sans probl?me) ;<br />
   <strong> DATE</strong> : date (jour, mois, ann?e).<br />
<br />
<span class="notice">Toute table doit poss?der un champ qui joue le r?le de cl? primaire. La cl? primaire permet d'identifier de mani?re unique une entr?e dans la table. En g?n?ral c'est le champ "id".</span><br />
<br />
<br />
<h3 class="formatter-title">Connexion ? la base de donn?es</h3><br />
<br />
<span class="notice">Pour cela on va utiliser MySQL. Les fonctions de l'extension mysql_ sont obsol?tes. Il faudrait donc utiliser l'extension mysqli_ ou PDO permettant de se connecter aussi bien ? MySQL que PostgreSQL ou Oracle. PDO est activ? par d?faut.</span><br />
<br />
<strong><span style="color:blue;">4 renseignement sont n?c?ssaires : </span></strong><br />
    <strong>le nom de l'h?te</strong> : c'est l'adresse de l'ordinateur o? MySQL est install? (comme une adresse IP) : localhost. <br />
    <strong>la base</strong> : c'est le nom de la base de donn?es ? laquelle vous voulez vous connecter. <br />
    <strong>le login</strong> : il permet de vous identifier.<br />
    <strong>le mot de passe</strong> : il y a des chances pour que le mot de passe soit le m?me que celui que vous utilisez pour acc?der au FTP. Renseignez-vous aupr?s de votre h?bergeur.<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//connexion et test de la pr?sence d'erreur</span>
try<span style="color: #8000FF;">&#123;</span>
    <span style="color: #000080;">$bdd</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> PDO<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'mysql:host=localhost;dbname=test'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'root'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">''</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
catch <span style="color: #8000FF;">&#40;</span>Exception <span style="color: #000080;">$e</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
        <a href="http://www.php.net/die"><span style="color: #0000FF; font-weight: bold;">die</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Erreur : '</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$e</span><span style="color: #8000FF;">-></span><span style="color: #000000;">getMessage</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="error">En cas d'erreur, PDO renvoie ce qu'on appelle une exception qui permet de ? capturer ? l'erreur. </span><br />
<br />
<h3 class="formatter-title">R?cup?rer les donn?es</h3><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
try<span style="color: #8000FF;">&#123;</span>
    <span style="color: #008000; font-style: italic;">// On se connecte ? MySQL</span>
    <span style="color: #000080;">$bdd</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> PDO<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'mysql:host=localhost;dbname=test'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'root'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">''</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
catch<span style="color: #8000FF;">&#40;</span>Exception <span style="color: #000080;">$e</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
    <span style="color: #008000; font-style: italic;">// En cas d'erreur, on affiche un message et on arr?te tout</span>
        <a href="http://www.php.net/die"><span style="color: #0000FF; font-weight: bold;">die</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Erreur : '</span><span style="color: #8000FF;">.</span><span style="color: #000080;">$e</span><span style="color: #8000FF;">-></span><span style="color: #000000;">getMessage</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// Si tout va bien, on peut continuer</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// On r?cup?re tout le contenu de la table jeux_video</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT * FROM jeux_video'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// On affiche chaque entr?e une ? une</span>
<span style="color: #0000FF; font-weight: bold;">while</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$donnees</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$reponse</span><span style="color: #8000FF;">-></span><span style="color: #000000;">fetch</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
    <p>
    <strong>Jeu</strong> : <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'nom'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span><br />
    Le possesseur de ce jeu est : <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'possesseur'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span>, et il le vend ? <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prix'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span> euros !<br />
    Ce jeu fonctionne sur <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'console'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span> et on peut y jouer ? <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'nbre_joueurs_max'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span> au maximum<br />
    <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'possesseur'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span> a laiss? ces commentaires sur <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'nom'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span> : <em><span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'commentaires'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span></em>
   </p>
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #8000FF;">&#125;</span>
 <span style="color: #000080;">$reponse</span><span style="color: #8000FF;">-></span><span style="color: #000000;">closeCursor</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// Termine le traitement de la requ?te</span>
&nbsp;
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Vous devez effectuer cet appel ? closeCursor() chaque fois que vous avez fini de traiter le retour d'une requ?te, afin d'?viter d'avoir des probl?mes ? la requ?te suivante. </span><br />
<br />
<br />
<h3 class="formatter-title">Crit?res de s?lection : WHERE, ORDER BY, LIMIT</h3><br />
<br />
    <strong>WHERE </strong> : permet de trier les donn?es;<br />
<br />
    <strong>ORDER BY</strong> : permet d'ordonn?es les donn?es;<br />
<br />
    <strong>LIMIT</strong> : s?lection d'une partie des r?sultats (par exemple les 20 premiers).<br />
<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #008000; font-style: italic;">/************************************************************************
WHERE : Trier
************************************************************************/</span>
<span style="color: #008000; font-style: italic;">//S?lectionner tous les champs de la table jeux_video lorsque le champ possesseur est ?gal ? Patrick</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT * FROM jeux_video WHERE possesseur=\'Patrick\''</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom, possesseur FROM jeux_video WHERE possesseur=\'Patrick\''</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//combinaison de plusieurs conditions: AND et OR</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">"SELECT * FROM jeux_video WHERE possesseur='Patrick' AND prix < 20"</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">/************************************************************************
ORDER BY : Ordonner
************************************************************************/</span>
<span style="color: #008000; font-style: italic;">//Les r?sultats sont ordonn?s par prix croissants</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom, prix FROM jeux_video ORDER BY prix'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//Les r?sultats sont ordonn?s par prix d?croissants</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom, prix FROM jeux_video ORDER BY prix DESC'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">/************************************************************************
LIMIT : s?lection d'une partie des r?sultats
************************************************************************/</span>
<span style="color: #008000; font-style: italic;">//S?lectionne les dix premi?res entr?es ;</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom FROM jeux_video LIMIT 0, 10'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//LIMIT 5, 10 : affiche de la sixi?me ? la quinzi?me entr?e ;</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom FROM jeux_video LIMIT 5, 10'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> 
<span style="color: #008000; font-style: italic;">/************************************************************************
Utiliser tous les crit?res en m?me temps.
ATTENTION : Il faut respecter l'ordre : WHERE, ORDER BY, LIMIT
************************************************************************/</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">"SELECT nom, possesseur, console, prix FROM jeux_video WHERE console='Xbox' OR console='PS2' ORDER BY prix DESC LIMIT 0,10"</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success">Il existe aussi le mot-cl? OR qui signifie ? ou ?.</span><br />
<br />
<span class="notice">Si on avait utilis? ORDER BY sur un champ contenant du texte, le classement aurait ?t? fait par ordre alphab?tique.</span><br />
<br />
<h3 class="formatter-title">Les requ?ttes pr?par?es</h3><br />
<br />
<span class="warning">Eviter de concatener des variables dans une requ?tte. </span><br />
<br />
<strong>La mauvaise id?e : concat?nation</strong><br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom FROM jeux_video WHERE possesseur=\''</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'possesseur'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'\''</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
Le syst?me de requ?tes pr?par?es est plus s?r mais aussi plus rapide pour la base de donn?es si la requ?te est ex?cut?e plusieurs fois.<br />
<br />
Dans un premier temps, la requ?te est pr?par?e sans sa partie variable, que l'on repr?sentera par un point d'interrogation. La requ?te est ensuite ex?cut?e ? l'aide des param?tres que l'on a indiqu?s sous forme d'array:<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
try<span style="color: #8000FF;">&#123;</span>
    <span style="color: #000080;">$bdd</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> PDO<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'mysql:host=localhost;dbname=test'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'root'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">''</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
catch<span style="color: #8000FF;">&#40;</span>Exception <span style="color: #000080;">$e</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
        <a href="http://www.php.net/die"><span style="color: #0000FF; font-weight: bold;">die</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Erreur : '</span><span style="color: #8000FF;">.</span><span style="color: #000080;">$e</span><span style="color: #8000FF;">-></span><span style="color: #000000;">getMessage</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">/************************************************************************
//Exemple 1 : une seule variable
************************************************************************/</span>
<span style="color: #000080;">$req</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">prepare</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom FROM jeux_video WHERE possesseur = ?'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">execute</span><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'possesseur'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">/************************************************************************
//Exemple 2 : Plusieurs variables (les param?tre doivent ?tre indiqu?es dans le bon ordre)
//lister les jeux appartenant ? une personne et dont le prix ne d?passe pas une certaine somme 
************************************************************************/</span>
<span style="color: #000080;">$req</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">prepare</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom FROM jeux_video WHERE possesseur = ? AND prix <= ?'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">execute</span><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'possesseur'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prix_max'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'<ul>'</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">while</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$donnees</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">fetch</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'<li>'</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'nom'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">' ('</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prix'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">' EUR)</li>'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'</ul>'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">closeCursor</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">/************************************************************************
//Exemple 3 : Avec des marqueurs nominatifs (dans le cas o? la requette est trop longue)
************************************************************************/</span>
<span style="color: #000080;">$req</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">prepare</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom, prix FROM jeux_video WHERE possesseur = :possesseur AND prix <= :prixmax'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">execute</span><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'possesseur'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'possesseur'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'prixmax'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prix_max'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Traquer les erreurs</h3><br />
<br />
<span class="warning">Prenez l'habitude de rajouter le code or die(print_r($bdd->errorInfo())) sur la m?me ligne que votre requ?te pour afficher des d?tails sur l'erreur.</span><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Requ?tte simple</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom FROM jeux_video'</span><span style="color: #8000FF;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #0000FF; font-weight: bold;">die</span></a><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/print_r"><span style="color: #0000FF; font-weight: bold;">print_r</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">errorInfo</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//Requ?tte pr?par?e</span>
<span style="color: #000080;">$req</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">prepare</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT nom, prix FROM jeux_video WHERE possesseur = :possesseur'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">execute</span><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'possesseur'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Patrick'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'prixmax'</span> <span style="color: #8000FF;">=></span> <span style="color: #FF8000;">20</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #0000FF; font-weight: bold;">die</span></a><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/print_r"><span style="color: #0000FF; font-weight: bold;">print_r</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">errorInfo</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Supposons que j'ai mal ?cris le nom du champ. L'erreur affich?e sera : </span></strong><br />
<br />
<span class="formatter-code">Code :</span><div class="code"><code><span style="color: #000000">
Unknown&nbsp;column&nbsp;'champinconnu'&nbsp;in&nbsp;'field&nbsp;list'</span>
</code></div><br />
<br />
<br />
<h3 class="formatter-title">?crire des donn?es</h3><br />
<br />
 <h4 class="formatter-title">INSERT : Ajouter des donn?es</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
try<span style="color: #8000FF;">&#123;</span>
    <span style="color: #000080;">$bdd</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> PDO<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'mysql:host=localhost;dbname=test'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'root'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">''</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
catch<span style="color: #8000FF;">&#40;</span>Exception <span style="color: #000080;">$e</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
        <a href="http://www.php.net/die"><span style="color: #0000FF; font-weight: bold;">die</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Erreur : '</span><span style="color: #8000FF;">.</span><span style="color: #000080;">$e</span><span style="color: #8000FF;">-></span><span style="color: #000000;">getMessage</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// On ajoute une entr?e dans la table jeux_video</span>
<span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><a href="http://www.php.net/exec"><span style="color: #0000FF; font-weight: bold;">exec</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'INSERT INTO jeux_video(ID, nom, possesseur, console, prix, nbre_joueurs_max, commentaires) 
                                                    VALUES('</span><span style="color: #808080;">', \'Battlefield 1942\', \'Patrick\', \'PC\', 45, 50, \'2nde guerre mondiale\')'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Le jeu a bien ?t? ajout? !'</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><br />
On commence par les mots-cl?s INSERT INTO,  suivis ensuite par le nom de la table (ici jeux_video), puis les noms des champs dans lesquels vous souhaitez placer des informations. On inscrit VALUES suivi des valeurs ? ins?rer dans le m?me ordre que les champs que l'on a indiqu?s.<br />
<br />
Pour le premier champ (ID), les es apostrophes sont vides. C'est voulu : le champ a la propri?t? auto_increment, MySQL mettra donc le num?ro d'ID lui-m?me<br />
</span><br />
<br />
<strong><span style="color:blue;">Insertion de donn?es variables gr?ce ? une requ?te pr?par?e</span></strong><br />
<br />
Le principe est le m?me que dans le chapitre pr?c?dent<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$req</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">prepare</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'INSERT INTO jeux_video(nom, possesseur, console, prix, nbre_joueurs_max, commentaires) 
                                                      VALUES(:nom, :possesseur, :console, :prix, :nbre_joueurs_max, :commentaires)'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">execute</span><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span>
    <span style="color: #808080;">'nom'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$nom</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'possesseur'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$possesseur</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'console'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$console</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'prix'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$prix</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'nbre_joueurs_max'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$nbre_joueurs_max</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'commentaires'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$commentaires</span>
    <span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'Le jeu a bien ?t? ajout? !'</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">UPDATE : Modifier des donn?es</h4> <br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Le nombre de lignes modifi? est renvoy?</span>
<span style="color: #000080;">$nb_modifs</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><a href="http://www.php.net/exec"><span style="color: #0000FF; font-weight: bold;">exec</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'UPDATE jeux_video SET possesseur = \'Florent\' WHERE possesseur = \'Michel\''</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$nb_modifs</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">' entr?es ont ?t? modifi?es !'</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">//===Requ?te pr?par?e==</span>
<span style="color: #000080;">$req</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">prepare</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'UPDATE jeux_video SET prix = :nvprix, nbre_joueurs_max = :nv_nb_joueurs WHERE nom = :nom_jeu'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">execute</span><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span>
    <span style="color: #808080;">'nvprix'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$nvprix</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'nv_nb_joueurs'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$nv_nb_joueurs</span><span style="color: #8000FF;">,</span>
    <span style="color: #808080;">'nom_jeu'</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$nom_jeu</span>
    <span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">DELETE : Supprimer des donn?es</h4> <br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video <span style="color: #993333; font-weight: bold;">WHERE</span> nom<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Battlefield 1942'</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Les fonctions SQL</h3><br />
<br />
 <h4 class="formatter-title">Les fonctions scalaires : UPPER, LOWER, LENGTH, ROUND</h4> <br />
<br />
Les fonctions scalaires modifient les valeurs.<br />
<br />
<strong><span style="color:blue;">Exemple : Conversion d'un champ en majuscule</span></strong><br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT UPPER(nom) AS nom_maj FROM jeux_video'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">while</span> <span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$donnees</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$reponse</span><span style="color: #8000FF;">-></span><span style="color: #000000;">fetch</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'nom_maj'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'<br />'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
&nbsp;
<span style="color: #000080;">$reponse</span><span style="color: #8000FF;">-></span><span style="color: #000000;">closeCursor</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Les autres fonctions s'utilisent de la m?me mani?re:</span></strong><br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">-- Conversion du champ  en majuscule</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> nom_maj <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video
<span style="color: #808080; font-style: italic;">-- Conversion du champ  en minuscule</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">LOWER</span><span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> nom_min <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video
<span style="color: #808080; font-style: italic;">-- Compte le nombre de caract?res</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">LENGTH</span><span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> longueur_nom <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video
<span style="color: #808080; font-style: italic;">-- Arrondi un nombre d?cimal</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> ROUND<span style="color: #66cc66;">&#40;</span>prix<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> prix_arrondi <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Vous pouvez aussi r?cup?rer le contenu des autres champs comme avant sans forc?ment leur appliquer une fonction :<br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> nom_maj<span style="color: #66cc66;">,</span> possesseur<span style="color: #66cc66;">,</span> console<span style="color: #66cc66;">,</span> prix <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video</pre></pre></div><br />
</span><br />
<br />
<br />
<span class="notice">Une liste d?taill?e des fonctions est disponible <a href="http://dev.mysql.com/doc/refman/5.0/en/functions.html">ici</a></span><br />
<br />
 <h4 class="formatter-title">Les fonctions d?agr?gats : AVG, SUM, MAX, MIN, COUNT</h4> <br />
<br />
Les fonctions d'agr?gats font des op?rations.<br />
<br />
<strong><span style="color:blue;">Exemple : calcul de la moyenne</span></strong><br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$reponse</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">query</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT AVG(prix) AS prix_moyen FROM jeux_video'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #000080;">$donnees</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$reponse</span><span style="color: #8000FF;">-></span><span style="color: #000000;">fetch</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'prix_moyen'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #000080;">$reponse</span><span style="color: #8000FF;">-></span><span style="color: #000000;">closeCursor</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="error"><br />
Vous ne devez pas r?cup?rer d'autres champs de la table quand vous utilisez une fonction d'agr?gat, contrairement ? tout ? l'heure avec les fonctions scalaires.<br />
</span><br />
<br />
<strong><span style="color:blue;">Les autres fonctions s'utilisent de la m?me mani?re:</span></strong><br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">-- AVG : Calcul de la moyenne</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> AVG<span style="color: #66cc66;">&#40;</span>prix<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> prix_moyen <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video
<span style="color: #808080; font-style: italic;">-- SUM : Additionner les valeurs</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>prix<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> prix_total <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video <span style="color: #993333; font-weight: bold;">WHERE</span> possesseur<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Patrick'</span>
<span style="color: #808080; font-style: italic;">-- MAX : retourner la valeur maximale</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>prix<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> prix_max <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video
<span style="color: #808080; font-style: italic;">-- MIN : retourner la valeur minimale</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">MIN</span><span style="color: #66cc66;">&#40;</span>prix<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> prix_min <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video
<span style="color: #808080; font-style: italic;">-- COUNT : compter le nombre d'entr?es</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> nbjeux <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> nbjeux <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video <span style="color: #993333; font-weight: bold;">WHERE</span> possesseur<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Florent'</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Il est possible de compter le nombre de valeurs distinctes sur un champ pr?cis.<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> possesseur<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> nbpossesseurs <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video</pre></pre></div><br />
</span><br />
<br />
 <h4 class="formatter-title">GROUP BY et HAVING : groupement de donn?es</h4> <br />
<br />
<strong><span style="color:blue;">GROUP BY est utilis? pour obtenir des informations int?ressantes sur des groupes de donn?es.</span></strong><br />
<br />
<span class="warning">Il faut utiliser GROUP BY en m?me temps qu'une fonction d'agr?gat, sinon il ne sert ? rien.</span><br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">-- Ici, on r?cup?re le prix moyen et la console, et on choisit de grouper par console</span>
<span style="color: #808080; font-style: italic;">--On a la liste des consoles et le prix moyen des jeux associ?s.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> AVG<span style="color: #66cc66;">&#40;</span>prix<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> prix_moyen<span style="color: #66cc66;">,</span> console <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> console
&nbsp;</pre></pre></div><br />
<br />
<span style="color:blue;">HAVING est utilis? pour filtrer les donn?es ? la fin des op?rations.</span><br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">--on r?cup?re uniquement la liste des consoles et leur prix moyen si ce prix moyen ne d?passe pas 10 euros.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> AVG<span style="color: #66cc66;">&#40;</span>prix<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> prix_moyen<span style="color: #66cc66;">,</span> console <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> console <span style="color: #993333; font-weight: bold;">HAVING</span> prix_moyen <span style="color: #66cc66;"><=</span> <span style="color: #cc66cc;">10</span>
<span style="color: #808080; font-style: italic;">--exemple 2 : combiner GROUP BY et HAVING</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> AVG<span style="color: #66cc66;">&#40;</span>prix<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> prix_moyen<span style="color: #66cc66;">,</span> console <span style="color: #993333; font-weight: bold;">FROM</span> jeux_video <span style="color: #993333; font-weight: bold;">WHERE</span> possesseur<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Patrick'</span> <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> console <span style="color: #993333; font-weight: bold;">HAVING</span> prix_moyen <span style="color: #66cc66;"><=</span> <span style="color: #cc66cc;">10</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="error"><br />
HAVING ne doit s'utiliser que sur le r?sultat d'une fonction d'agr?gat. Voil? pourquoi on l'utilise ici sur prix_moyen et non sur console.<br />
</span><br />
<br />
<br />
<h3 class="formatter-title">Les dates en SQL</h3><br />
<br />
 <h4 class="formatter-title">Les champs de type date</h4> <br />
<br />
Plusieurs types de champs existent. Les plus utilis?s sont :<br />
<br />
<strong>DATE</strong> : stocke une date au format AAAA-MM-JJ (Ann?e-Mois-Jour) ;<br />
<strong>DATETIME</strong> : stocke la combinaison d'une date et d'un moment de la journ?e au format AAAA-MM-JJ HH:MM:SS. <br />
<br />
<span class="error"><br />
Lorsque vous cr?ez votre table MySQL, nommer le champ comme ceci : date_creation, ou encore date_modification. Ne jamais utiliser "date" tout court. Cela peut g?n?rer des erreur car date est une fonction MySQL.<br />
</span><br />
<br />
 <h4 class="formatter-title">Utilisation des dates</h4> <br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">-- Affiche la liste des messages post?s le 02/04/2010 </span>
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #993333; font-weight: bold;">FROM</span> minichat <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'2010-04-02'</span>
<span style="color: #808080; font-style: italic;">-- Affiche la liste des messages post?s le 02/04/2010 ? 15h28min22s</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #993333; font-weight: bold;">FROM</span> minichat <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'2010-04-02 15:28:22'</span>
<span style="color: #808080; font-style: italic;">-- Affiche la liste des messages post?s apr?s le 02/04/2010 ? 15h28min22s</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #993333; font-weight: bold;">FROM</span> minichat <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #66cc66;">>=</span> <span style="color: #ff0000;">'2010-04-02 15:28:22'</span>
<span style="color: #808080; font-style: italic;">-- Affiche la liste des messages post?s entre deux dates:</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #993333; font-weight: bold;">FROM</span> minichat <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #66cc66;">>=</span> <span style="color: #ff0000;">'2010-04-02 00:00:00'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #66cc66;"><=</span> <span style="color: #ff0000;">'2010-04-18 00:00:00'</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #993333; font-weight: bold;">FROM</span> minichat <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #ff0000;">'2010-04-02 00:00:00'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #ff0000;">'2010-04-18 00:00:00'</span>
<span style="color: #808080; font-style: italic;">-- Ins?rer un message avec date</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> minichat<span style="color: #66cc66;">&#40;</span>pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DATE</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Mateo'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Message !'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'2010-04-02 16:32:22'</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Les fonctions de gestions des dates</h4> <br />
<br />
 <h4 class="formatter-title">NOW() : obtenir la date et l'heure actuelles</h4> <br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">-- La date sera alors remplac?e par la date et l'heure actuelles au format AAAA-MM-JJ HH:MM:SS</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> minichat<span style="color: #66cc66;">&#40;</span>pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DATE</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Mateo'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Message !'</span><span style="color: #66cc66;">,</span> NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="notice">Il existe aussi les fonctions CURDATE() et CURTIME() qui retournent respectivement uniquement la date (AAAA-MM-JJ) et l'heure (HH:MM:SS).</span><br />
<br />
 <h4 class="formatter-title">DAY(), MONTH(), YEAR() : extraire le jour, le mois ou l'ann?e</h4> <br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DATE</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> jour <span style="color: #993333; font-weight: bold;">FROM</span> minichat
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">HOUR(), MINUTE(), SECOND() : extraire les heures, minutes, secondes</h4> <br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">HOUR</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DATE</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> heure <span style="color: #993333; font-weight: bold;">FROM</span> minichat</pre></pre></div><br />
<br />
 <h4 class="formatter-title">DATE_FORMAT : formater une date</h4> <br />
<br />
DATE_FORMAT vous permet d'adapter directement la date au format que vous pr?f?rez.<br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">-- R?cup?ration des dates avec un champ nomm? date sous la forme 11/03/2010 15h47min49s.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> DATE_FORMAT<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DATE</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'%d/%m/%Y %Hh%imin%ss'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DATE</span> <span style="color: #993333; font-weight: bold;">FROM</span> minichat
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">DATE_ADD et DATE_SUB : ajouter ou soustraire des dates</h4> <br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">-- Afficher une date d'expiration du message :  la date o? a ?t? post? le message + 15 jours</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> DATE_ADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DATE</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">INTERVAL</span> <span style="color: #cc66cc;">15</span> <span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> date_expiration <span style="color: #993333; font-weight: bold;">FROM</span> minichat
<span style="color: #808080; font-style: italic;">-- Indiquer que les messages expirent dans deux mois </span>
<span style="color: #993333; font-weight: bold;">SELECT</span> pseudo<span style="color: #66cc66;">,</span> message<span style="color: #66cc66;">,</span> DATE_ADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DATE</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">INTERVAL</span> <span style="color: #cc66cc;">2</span> <span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> date_expiration <span style="color: #993333; font-weight: bold;">FROM</span> minichat
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Le mot-cl? INTERVAL ne doit pas ?tre chang? ; en revanche, vous pouvez remplacer DAY par MONTH, YEAR, HOUR, MINUTE, SECOND, etc.</span><br />
<br />
<br />
<h3 class="formatter-title">Les jointures entre table</h3><br />
<br />
Soit deux tables : <strong>jeux_videos</strong>(contenant description et prix des jeux) et <strong>proprietaires</strong> (contenant le nom et adresse des propri?taires de jeux).<br />
Les jeux et leurs propri?taires ont une correspondance via le champ ID_proprietaire (de la table jeux_video) et le champ ID (de la table proprietaires)<br />
<br />
<strong>Les jointures internes :</strong> elles ne s?lectionnent que les donn?es qui ont une correspondance entre les deux tables ;<br />
<strong>Les jointures externes :</strong> elles s?lectionnent toutes les donn?es, m?me si certaines n'ont pas de correspondance dans l'autre table.<br />
<br />
 <h4 class="formatter-title">Les jointures internes</h4> <br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">--===================================</span>
<span style="color: #808080; font-style: italic;">-- Jointure interne avec WHERE</span>
<span style="color: #808080; font-style: italic;">--===================================</span>
<span style="color: #808080; font-style: italic;">--On demande clairement de r?cup?rer le nom du jeu et le pr?nom du propri?taire avec cette requ?te.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> jeux_video<span style="color: #66cc66;">.</span>nom<span style="color: #66cc66;">,</span> proprietaires<span style="color: #66cc66;">.</span>prenom
<span style="color: #993333; font-weight: bold;">FROM</span> proprietaires<span style="color: #66cc66;">,</span> jeux_video
<span style="color: #993333; font-weight: bold;">WHERE</span> jeux_video<span style="color: #66cc66;">.</span>ID_proprietaire <span style="color: #66cc66;">=</span> proprietaires<span style="color: #66cc66;">.</span>ID
<span style="color: #808080; font-style: italic;">--===================================</span>
<span style="color: #808080; font-style: italic;">-- Utilisation des alias</span>
<span style="color: #808080; font-style: italic;">--===================================</span>
<span style="color: #808080; font-style: italic;">-- il est possible de donner des alias aux noms de champs et noms de tables</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> j<span style="color: #66cc66;">.</span>nom <span style="color: #993333; font-weight: bold;">AS</span> nom_jeu<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>prenom <span style="color: #993333; font-weight: bold;">AS</span> prenom_proprietaire
<span style="color: #993333; font-weight: bold;">FROM</span> proprietaires <span style="color: #993333; font-weight: bold;">AS</span> p<span style="color: #66cc66;">,</span> jeux_video <span style="color: #993333; font-weight: bold;">AS</span> j
<span style="color: #993333; font-weight: bold;">WHERE</span> j<span style="color: #66cc66;">.</span>ID_proprietaire <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
<span style="color: #808080; font-style: italic;">--Le mot cl? AS est facultatif</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> j<span style="color: #66cc66;">.</span>nom nom_jeu<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>prenom prenom_proprietaire
<span style="color: #993333; font-weight: bold;">FROM</span> proprietaires p<span style="color: #66cc66;">,</span> jeux_video j
<span style="color: #993333; font-weight: bold;">WHERE</span> j<span style="color: #66cc66;">.</span>ID_proprietaire <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
<span style="color: #808080; font-style: italic;">--===================================</span>
<span style="color: #808080; font-style: italic;">-- Jointure interne avec JOIN</span>
<span style="color: #808080; font-style: italic;">--===================================</span>
<span style="color: #808080; font-style: italic;">--On r?cup?re les donn?es depuis une table principale (proprietaires) et on fait une jointure interne avec une autre table (jeux_video)</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> j<span style="color: #66cc66;">.</span>nom nom_jeu<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>prenom prenom_proprietaire
<span style="color: #993333; font-weight: bold;">FROM</span> proprietaires p
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> jeux_video j
<span style="color: #993333; font-weight: bold;">ON</span> j<span style="color: #66cc66;">.</span>ID_proprietaire <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
<span style="color: #808080; font-style: italic;">--===================================</span>
<span style="color: #808080; font-style: italic;">-- Introduire des filtres avec WHERE, ORDER BY, LIMIT</span>
<span style="color: #808080; font-style: italic;">--===================================</span>
<span style="color: #808080; font-style: italic;">-- R?cup?re le nom du jeu et le pr?nom du propri?taire dans les tables proprietaires et jeux_video, </span>
<span style="color: #808080; font-style: italic;">-- la liaison entre les tables se fait entre les champs ID_proprietaire et ID,</span>
<span style="color: #808080; font-style: italic;">-- prends uniquement les jeux qui tournent sur PC, </span>
<span style="color: #808080; font-style: italic;">--trie-les par prix d?croissants et ne prends que les 10 premiers. </span>
<span style="color: #993333; font-weight: bold;">SELECT</span> j<span style="color: #66cc66;">.</span>nom nom_jeu<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>prenom prenom_proprietaire
<span style="color: #993333; font-weight: bold;">FROM</span> proprietaires p
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> jeux_video j
<span style="color: #993333; font-weight: bold;">ON</span> j<span style="color: #66cc66;">.</span>ID_proprietaire <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
<span style="color: #993333; font-weight: bold;">WHERE</span> j<span style="color: #66cc66;">.</span>console <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'PC'</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> prix <span style="color: #993333; font-weight: bold;">DESC</span>
<span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">10</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
WHERE et JOIN permettent d'effectuer des jointures internes. Il est conseill? d'utiliser JOIN qui est beaucoup plus efficace.<br />
</span><br />
<br />
<br />
 <h4 class="formatter-title">Les jointures externes</h4> <br />
<br />
Les jointures externes permettent de r?cup?rer toutes les donn?es, m?me celles qui n'ont pas de correspondance.<br />
<br />
<strong><span style="color:blue;">LEFT JOIN : r?cup?rer toute la table de gauche</span></strong><br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> j<span style="color: #66cc66;">.</span>nom nom_jeu<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>prenom prenom_proprietaire
<span style="color: #993333; font-weight: bold;">FROM</span> proprietaires p
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> jeux_video j
<span style="color: #993333; font-weight: bold;">ON</span> j<span style="color: #66cc66;">.</span>ID_proprietaire <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><br />
proprietaires est appel?e la ? table de gauche ? et jeux_video la ? table de droite ?. Le LEFT JOIN demande ? r?cup?rer tout le contenu de la table de gauche, donc tous les propri?taires, m?me si ces derniers n'ont pas d'?quivalence dans la table jeux_video.<br />
</span><br />
<br />
<strong><span style="color:blue;">RIGHT JOIN : r?cup?rer toute la table de droite</span></strong><br />
<br />
<span class="formatter-code">Code SQL :</span><div class="code"><pre style="display:inline;"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> j<span style="color: #66cc66;">.</span>nom nom_jeu<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>prenom prenom_proprietaire
<span style="color: #993333; font-weight: bold;">FROM</span> proprietaires p
<span style="color: #993333; font-weight: bold;">RIGHT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> jeux_video j
<span style="color: #993333; font-weight: bold;">ON</span> j<span style="color: #66cc66;">.</span>ID_proprietaire <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
&nbsp;</pre></pre></div><br />
<br />
<br />
[page]Les expressions r?guli?res[/page]<br />
<br />
Nous allons utiliser les expressions r?guli?res de type PCRE issues du langage Perl.<br />
<br />
Les fonctions qui nous int?ressent sont :<br />
preg_grep ; preg_split ; preg_quote ; preg_match ; preg_match_all ; preg_replace ;    preg_replace_callback.<br />
<br />
<h3 class="formatter-title">Recherches simples</h3><br />
<br />
<span class="warning">une regex (Expression r?guli?re) est toujours entour?e de caract?res sp?ciaux appel?s d?limiteurs.</span><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Recherche du mot guitare</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #0000FF; font-weight: bold;">preg_match</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">"#guitare#"</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">"J'aime jouer de la guitare."</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>  <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'VRAI'</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">else</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'FAUX'</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">/*==========================================
//Recherche insensible ? la casse : utilisation de i
==========================================*/</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #0000FF; font-weight: bold;">preg_match</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">"#guitare#i"</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">"J'aime jouer de la guitare."</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>  <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'VRAI'</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">/*==========================================
//Le symbole ou : |
==========================================*/</span>
<span style="color: #008000; font-style: italic;">//Recherche du mot guitare ou piano</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #0000FF; font-weight: bold;">preg_match</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">"#guitare|piano#"</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">"J'aime jouer de la guitare."</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>  <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'VRAI'</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">/*==========================================
//D?but (^) et fin($) de cha?ne
==========================================*/</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #0000FF; font-weight: bold;">preg_match</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">"#^guitare#"</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">"J'aime jouer de la guitare."</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>  <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'VRAI'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//si la chaine commence par guitare</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #0000FF; font-weight: bold;">preg_match</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">"#guitare$#"</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">"J'aime jouer de la guitare."</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>  <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'VRAI'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//si la chaine finit par guitare</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #0000FF; font-weight: bold;">preg_match</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">"#^guitare$#"</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">"J'aime jouer de la guitare."</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>  <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'VRAI'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">//La cha?ne doit contenir uniquement ? guitare ?</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Les classes de caract?res</h3><br />
    <br />
<strong>#gr[io]s#</strong>: Une des lettres ? l'int?rieur peut convenir. Notre regex reconna?t deux mots : ? gris ? et ? gros ?.<br />
<strong>#[aeiouy]$#</strong> : Notre regex se termine par une voyelle<br />
<strong>[a-z]</strong> : Toutes les lettres de l'alphabet en minuscule<br />
<strong>[a-e]</strong> : Les lettres de a ? e<br />
<strong>[0-9]</strong> : Les chiffres de 0 ? 9.<br />
[a-z0-9]. Cela signifie ? N'importe quelle lettre (minuscule) OU un chiffre ?.<br />
<br />
<span class="notice">Si vous ne voulez PAS des caract?res que vous ?num?rez dans votre classe, vous devrez placer le symbole ? ^ ? au d?but de la classe.</span><br />
<br />
<strong>#[^0-9]# </strong> : Je ne veux pas de chiffre<br />
<strong>#[^A-Z0-9]#</strong> : Ni majuscule, ni chiffre<br />
<strong>#^[^a-z]#</strong> : Ne commence pas par une minuscule<br />
<strong>#[^aeiouy]$#</strong>: Ne se termine pas par une voyelle<br />
<br />
<h3 class="formatter-title">Les quantificateurs</h3><br />
<br />
<strong><span style="color:blue;">Trois symboles ? retenir : </span></strong><br />
<br />
<strong>? (point d'interrogation) </strong>: La lettre est facultative. Elle peut y ?tre 0 ou 1 fois. Ainsi, #a?# reconna?t 0 ou 1 ? a ? ;<br />
<strong> + (signe plus) </strong>: la lettre est obligatoire. Elle peut appara?tre 1 ou plusieurs fois.  Ainsi, #a+# reconna?t ? a ?, ? aa ?, ? aaa ?, ? aaaa ?, etc. ;<br />
<strong> * (?toile)</strong> : la lettre est facultative. Elle peut appara?tre 0, 1 ou plusieurs fois.  Ainsi, #a*# reconna?t ? a ?, ? aa ?, ? aaa ?, ? aaaa ?, etc. Mais s'il n'y a pas de ? a ?, ?a fonctionne aussi !<br />
<br />
<h3 class="formatter-title">?tre plus pr?cis gr?ce aux accolades</h3><br />
<br />
{3} : la lettre (ou le groupe de lettres s'il est entre parenth?ses) doit ?tre r?p?t?e 3 fois exactement.<br />
#a{3}# fonctionne donc pour la cha?ne ? aaa ?.<br />
<br />
{3,5} : ici, on a plusieurs possibilit?s. On peut avoir la lettre de 3 ? 5 fois.<br />
#a{3,5}# fonctionne pour ? aaa ?, ? aaaa ?, ? aaaaa ?.<br />
<br />
{3,} : si vous mettez une virgule, mais pas de 2e nombre, ?a veut dire qu'il peut y en avoir jusqu'? l'infini. Ici, cela signifie ? 3 fois ou plus ?.<br />
#a{3,} fonctionne pour ? aaa ?, ? aaaa ?, ? aaaaa ?, ? aaaaaa ?, etc. <br />
<br />
<br />
<span class="success"><br />
Si vous faites attention, vous remarquez que :<br />
    ? revient ? ?crire {0,1} ;<br />
    + revient ? ?crire {1,} ;<br />
    * revient ? ?crire {0,}.<br />
</span><br />
<br />
<h3 class="formatter-title">Les caract?res sp?ciaux</h3><br />
<br />
# ! ^ $ ( ) [ ] { } ? + * . \ |<br />
<br />
Pour les ?chapper dans une expression recherch?e, Il va falloir l'?chapper. Cela signifie que vous devez placer en fait un antislash ? \ ? devant un caract?re sp?cial.<br />
<br />
<span class="warning">Et si vous voulez ajouter le tiret dans la liste des caract?res possibles ? Eh bien il suffit de le mettre soit au d?but de la classe, soit ? la fin. Par exemple : [a-z0-9-] permet de chercher une lettre, un chiffre ou un tiret.</span><br />
<br />
<h3 class="formatter-title">Capture et remplacement</h3><br />
<br />
Nous allons utiliser la fonction preg_replace pour capturer et remplacer une cha?ne. La cha?ne ? capturer est mise entre parenth?se.<br />
<br />
<span style="color:blue;">Exemple:</span><br />
#\[b\](.+)\[/b\]# : Chercher dans la cha?ne un [ b ], suivi d'un ou plusieurs caract?re(s) (le point permet de dire ? n'importe lesquels ?), suivi(s) d'un [ /b ]<br />
<br />
<span class="notice">A chaque fois qu'il y a une parenth?se, cela cr?e une variable appel?e $1 (pour la premi?re parenth?se), $2 pour la seconde, etc.<br />
On va ensuite se servir de ces variables pour modifier la cha?ne (faire un remplacement).</span><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Met en gras les mots plac?s entre [b][/b]</span>
<span style="color: #000080;">$texte</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #0000FF; font-weight: bold;">preg_replace</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'#\[b\](.+)\[/b\]#i'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'<strong>$1</strong>'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$texte</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Les options</span></strong><br />
i : pour accepter les majuscules comme les minuscules ([B ] et [b ]) ;<br />
s : pour que le ? point ? fonctionne aussi pour les retours ? la ligne (pour que le texte puisse ?tre en gras sur plusieurs lignes) ;<br />
U : le U majuscule est une option que vous ne connaissez pas et qui signifie ? Ungreedy ? (? pas gourmand ?). Sachez que, grosso modo, ?a ne marcherait pas correctement s'il y avait plusieurs [b ] dans votre texte.? sans activer l'option Ungreedy, la regex aurait voulu mettre en gras tout ce qu'il y a entre le premier [b ] et le dernier [/b ].<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$texte</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #0000FF; font-weight: bold;">preg_replace</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'#\[b\](.+)\[/b\]#isU'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'<strong>$1</strong>'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$texte</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$texte</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #0000FF; font-weight: bold;">preg_replace</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'#\[i\](.+)\[/i\]#isU'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'<em>$1</em>'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$texte</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
[page]La programmation orient?e objet[/page]<br />
<br />
<h3 class="formatter-title">Cr?er une class</h3><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">class</span> Membre
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">private</span> <span style="color: #000080;">$pseudo</span><span style="color: #8000FF;">;</span>
    <span style="color: #0000FF; font-weight: bold;">private</span> <span style="color: #000080;">$email</span><span style="color: #8000FF;">;</span>
    <span style="color: #0000FF; font-weight: bold;">private</span> <span style="color: #000080;">$signature</span><span style="color: #8000FF;">;</span>
    <span style="color: #0000FF; font-weight: bold;">private</span> <span style="color: #000080;">$actif</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">//fonction constructeur</span>
<span style="color: #008000; font-style: italic;">//Le r?le d'une fonction constructeur est justement de construire l'objet,</span>
<span style="color: #008000; font-style: italic;">// c'est-?-dire de le pr?parer ? une premi?re utilisation.</span>
<span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> __construct<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$idMembre</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #008000; font-style: italic;">// R?cup?rer en base de donn?es les infos du membre</span>
        <span style="color: #008000; font-style: italic;">// SELECT pseudo, email, signature, actif FROM membres WHERE id = ...</span>
&nbsp;
        <span style="color: #008000; font-style: italic;">// D?finir les variables avec les r?sultats de la base</span>
        <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">pseudo</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'pseudo'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span>
        <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">email</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$donnees</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'email'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span>
        <span style="color: #008000; font-style: italic;">// etc.</span>
    <span style="color: #8000FF;">&#125;</span> 
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> envoyerEMail<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$titre</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$message</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <a href="http://www.php.net/mail"><span style="color: #0000FF; font-weight: bold;">mail</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">email</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$titre</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$message</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> bannir<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">actif</span> <span style="color: #8000FF;">=</span> <span style="">false</span><span style="color: #8000FF;">;</span>
        <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">envoyerEMail</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Vous avez ?t? banni'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'Ne revenez plus !'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
  <span style="color: #008000; font-style: italic;">//les getters et les setters</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> getPseudo<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">pseudo</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> setPseudo<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$nouveauPseudo</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">!</span><a href="http://www.php.net/empty"><span style="color: #0000FF; font-weight: bold;">empty</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$nouveauPseudo</span><span style="color: #8000FF;">&#41;</span> AND <a href="http://www.php.net/strlen"><span style="color: #0000FF; font-weight: bold;">strlen</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$nouveauPseudo</span><span style="color: #8000FF;">&#41;</span> <span style="color: #8000FF;"><</span> <span style="color: #FF8000;">15</span><span style="color: #8000FF;">&#41;</span>
        <span style="color: #8000FF;">&#123;</span>
            <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">pseudo</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$nouveauPseudo</span><span style="color: #8000FF;">;</span>
        <span style="color: #8000FF;">&#125;</span>
    <span style="color: #8000FF;">&#125;</span>  
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Cr?er un objet</h3><br />
<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">include_once</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Membre.class.php'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #000080;">$membre</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> Membre<span style="color: #8000FF;">&#40;</span><span style="color: #FF8000;">32</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$membre</span><span style="color: #8000FF;">-></span><span style="color: #000000;">setPseudo</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'M@teo21'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$membre</span><span style="color: #8000FF;">-></span><span style="color: #000000;">getPseudo</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">', je vais te bannir !'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$membre</span><span style="color: #8000FF;">-></span><span style="color: #000000;">bannir</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> 
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="notice"><br />
Pour d?truire un objet, ou toute autre variable, on peut le faire ? la main avec la fonction unset() :<br />
<?php<br />
unset($membre);<br />
?><br />
</span><br />
<br />
<h3 class="formatter-title">H?ritage</h3><br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">include_once</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Membre.class.php'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">class</span> Admin <span style="color: #0000FF; font-weight: bold;">extends</span> Membre
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">private</span> <span style="color: #000080;">$couleur</span><span style="color: #8000FF;">;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> setCouleur<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #008000; font-style: italic;">// ...</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> getCouleur<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #008000; font-style: italic;">// ...</span>
    <span style="color: #8000FF;">&#125;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"> C'est cela l'h?ritage : nous avons maintenant une classe Admin qui poss?de toutes les variables et fonctions de Membre, et nous allons pouvoir en d?finir de nouvelles qui seront propres aux admins.</span><br />
<br />
<h3 class="formatter-title">Les droits d'acc?s</h3><br />
<br />
Il y a trois droits d'acc?s ? conna?tre :<br />
<br />
    public : tout le monde peut acc?der ? l'?l?ment ;<br />
    private : personne (? part la classe elle-m?me) n'a le droit d'acc?der ? l'?l?ment ;<br />
    protected : identique ? private, sauf qu'un ?l?ment ayant ce droit d'acc?s dans une classe m?re sera accessible aussi dans les classes filles.<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #000080;">$membre</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> Membre<span style="color: #8000FF;">&#40;</span><span style="color: #FF8000;">4</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$membre</span><span style="color: #8000FF;">-></span><span style="color: #000000;">setPseudo</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'M@teo21'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// OK car setPseudo est public</span>
<span style="color: #000080;">$membre</span><span style="color: #8000FF;">-></span><span style="color: #000000;">pseudo</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'M@teo21'</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// Interdit car $pseudo est private</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div><br />
<br />
<span class="notice">Toutes les variables d'une classe doivent toujours ?tre priv?es ou prot?g?es.</span><br />
<br />
<br />
[page]Organiser son code selon l'architecture MVC[/page]<br />
<br />
<span style="color:blue;"><strong>Mod?le - Vue - Contr?leur</strong></span><br />
<br />
<strong> Mod?le</strong> : cette partie g?re les donn?es de votre site. On y trouve donc les requ?tes SQL.<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">function</span> get_billets<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$offset</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$limit</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">global</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">;</span>
    <span style="color: #000080;">$offset</span> <span style="color: #8000FF;">=</span> <span style="color: #8000FF;">&#40;</span>int<span style="color: #8000FF;">&#41;</span> <span style="color: #000080;">$offset</span><span style="color: #8000FF;">;</span>
    <span style="color: #000080;">$limit</span> <span style="color: #8000FF;">=</span> <span style="color: #8000FF;">&#40;</span>int<span style="color: #8000FF;">&#41;</span> <span style="color: #000080;">$limit</span><span style="color: #8000FF;">;</span>
&nbsp;
    <span style="color: #000080;">$req</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$bdd</span><span style="color: #8000FF;">-></span><span style="color: #000000;">prepare</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'SELECT id, titre, contenu, DATE_FORMAT(date_creation, \'%d/%m/%Y ? %Hh%imin%ss\') AS date_creation_fr FROM billets ORDER BY date_creation DESC LIMIT :offset, :limit'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">bindParam</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">':offset'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$offset</span><span style="color: #8000FF;">,</span> PDO<span style="color: #8000FF;">::</span><span style="color: #000000;">PARAM_INT</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">bindParam</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">':limit'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$limit</span><span style="color: #8000FF;">,</span> PDO<span style="color: #8000FF;">::</span><span style="color: #000000;">PARAM_INT</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">execute</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #000080;">$billets</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$req</span><span style="color: #8000FF;">-></span><span style="color: #000000;">fetchAll</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #000080;">$billets</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
&nbsp;</pre></pre></div><br />
<br />
<strong>Contr?leur</strong> : cette partie g?re la logique du code qui prend des d?cisions. Le contr?leur va demander au mod?le les donn?es, les analyser, prendre des d?cisions et renvoyer le texte ? afficher ? la vue. Le contr?leur contient exclusivement du PHP.<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">// On demande les 5 derniers billets (mod?le)</span>
<span style="color: #0000FF; font-weight: bold;">include_once</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'modele/blog/get_billets.php'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$billets</span> <span style="color: #8000FF;">=</span> get_billets<span style="color: #8000FF;">&#40;</span><span style="color: #FF8000;">0</span><span style="color: #8000FF;">,</span> <span style="color: #FF8000;">5</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// On effectue du traitement sur les donn?es (contr?leur)</span>
<span style="color: #008000; font-style: italic;">// Ici, on doit surtout s?curiser l'affichage</span>
<span style="color: #0000FF; font-weight: bold;">foreach</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$billets</span> <span style="color: #0000FF; font-weight: bold;">as</span> <span style="color: #000080;">$cle</span> <span style="color: #8000FF;">=></span> <span style="color: #000080;">$billet</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #000080;">$billets</span><span style="color: #8000FF;">&#91;</span><span style="color: #000080;">$cle</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'titre'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/htmlspecialchars"><span style="color: #0000FF; font-weight: bold;">htmlspecialchars</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$billet</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'titre'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #000080;">$billets</span><span style="color: #8000FF;">&#91;</span><span style="color: #000080;">$cle</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'contenu'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/nl2br"><span style="color: #0000FF; font-weight: bold;">nl2br</span></a><span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/htmlspecialchars"><span style="color: #0000FF; font-weight: bold;">htmlspecialchars</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$billet</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'contenu'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// On affiche la page (vue)</span>
<span style="color: #0000FF; font-weight: bold;">include_once</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'vue/blog/index.php'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;</pre></pre></div><br />
<br />
<strong>Vue </strong>: cette partie se concentre sur l'affichage. On y trouve essentiellement du code HTML mais aussi quelques boucles et conditions PHP tr?s simples.<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
        <title>Mon blog</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="vue/blog/style.css" rel="stylesheet" type="text/css" />
    </head>
&nbsp;
    <body>
        <h1>Mon super blog !</h1>
        <p>Derniers billets du blog :</p>
&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">foreach</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$billets</span> <span style="color: #0000FF; font-weight: bold;">as</span> <span style="color: #000080;">$billet</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
<div class="news">
    <h3>
        <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$billet</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'titre'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span>
        <em>le <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$billet</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'date_creation_fr'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span></em>
    </h3>
&nbsp;
    <p>
    <span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$billet</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'contenu'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span>
    <br />
    <em><a href="commentaires.php?billet=<span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$billet</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'id'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span>">Commentaires</a></em>
    </p>
</div>
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
</body>
</html>
&nbsp;</pre></pre></div><br />
<br />
<span style="color:blue;"><strong>Le contr?leur global du blog</strong></span><br />
Son r?le sera essentiellement de traiter les param?tres $_GET et d'appeler le contr?leur correspondant en fonction de la page demand?e. On peut aussi profiter de ce point ? central ? pour cr?er la connexion ? la base de donn?es.<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">include_once</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'modele/connexion_sql.php'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">!</span><a href="http://www.php.net/isset"><span style="color: #0000FF; font-weight: bold;">isset</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'section'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span> OR <span style="color: #000080;">$_GET</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'section'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">==</span> <span style="color: #808080;">'index'</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">include_once</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'controleur/blog/index.php'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><br />
Vous noterez que ce fichier PHP ne contient pas la balise de fermeture ?>. Celle-ci n'est en effet pas obligatoire, comme je vous l'ai dit plus t?t dans le cours. Je vous recommande de ne pas l'?crire surtout dans le mod?le et le contr?leur d'une architecture MVC. Cela permet d'?viter de f?cheux probl?mes li?s ? l'envoi de HTML avant l'utilisation de fonctions comme setCookie qui n?cessitent d'?tre appel?es avant tout code HTML.<br />
</span><br />
<br />
[page]Prot?gez un dossier avec .htacces[/page]<br />
<br />
<h3 class="formatter-title">Cr?er le fichier .htacces</h3><br />
<br />
Cr?er un fichier avec le nom ".htacces" dans le dossier et mettez-y le contenu suivant :<br />
<br />
<span class="formatter-code">Code :</span><div class="code"><code><span style="color: #000000">
<br />AuthName&nbsp;"Entrez&nbsp;vos&nbsp;identifiants"<br />AuthType&nbsp;Basic<br />AuthUserFile&nbsp;"/home/site/www/admin/.htpasswd"<br />Require&nbsp;valid-user<br /></span>
</code></div> <br />
<br />
<strong>AuthName </strong>: c'est le texte qui invitera l'utilisateur ? inscrire son login et son mot de passe. Vous pouvez personnaliser ce texte comme bon vous semble ;<br />
<strong>AuthUserFile</strong> : c'est le chemin absolu vers le fichier .htpasswd (que vous mettrez dans le m?me r?pertoire que le .htaccess).<br />
<br />
<span class="warning">Pour trouver le chemin absolu d'un fichier, utilisez la fonction PHP realpath<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <a href="http://www.php.net/realpath"><span style="color: #0000FF; font-weight: bold;">realpath</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'fichier.php'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></span><br />
<br />
<h3 class="formatter-title">Cr?er le fichier .htpasswd</h3><br />
<br />
Le .htpasswd va contenir la liste des personnes autoris?es ? acc?der aux pages du dossier. On y inscrit une personne par ligne, sous cette forme :<br />
<br />
<span class="formatter-code">Code :</span><div class="code"><code><span style="color: #000000">
login:mot_de_passe_crypt?</span>
</code></div><br />
<br />
<span class="warning">Pour crypter un mot de passe :<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span> <span style="color: #0000FF; font-weight: bold;">echo</span> <a href="http://www.php.net/crypt"><span style="color: #0000FF; font-weight: bold;">crypt</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'kangourou'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></span><br />
<br />
Ci-dessous une page php permettant de crypter automatiquement les mots de passe et d'afficher la ligne ? copier dans .htpasswd :<br />
<br />
<span class="formatter-code">Code PHP :</span><div class="code"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #8000FF;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #0000FF; font-weight: bold;">isset</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_POST</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'login'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span> AND <a href="http://www.php.net/isset"><span style="color: #0000FF; font-weight: bold;">isset</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_POST</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'pass'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #000080;">$login</span> <span style="color: #8000FF;">=</span> <span style="color: #000080;">$_POST</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'login'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">;</span>
    <span style="color: #000080;">$pass_crypte</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/crypt"><span style="color: #0000FF; font-weight: bold;">crypt</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$_POST</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'pass'</span><span style="color: #8000FF;">&#93;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span> <span style="color: #008000; font-style: italic;">// On crypte le mot de passe</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #808080;">'<p>Ligne ? copier dans le .htpasswd :<br />'</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$login</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">':'</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$pass_crypte</span> <span style="color: #8000FF;">.</span> <span style="color: #808080;">'</p>'</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">else</span> <span style="color: #008000; font-style: italic;">// On n'a pas encore rempli le formulaire</span>
<span style="color: #8000FF;">&#123;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;
<p>Entrez votre login et votre mot de passe pour le crypter.</p>
&nbsp;
<form method="post">
    <p>
        Login : <input type="text" name="login"><br />
        Mot de passe : <input type="text" name="pass"><br /><br />
&nbsp;
        <input type="submit" value="Crypter !">
    </p>
</form>
&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div>]]></description>
			<pubDate>Sun, 16 Jun 2013 11:10:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Redigez un document en LaTeX]]></title>
			<link>https://www.sthda.com/french/articles/19-latex/53-redigez-un-document-en-latex/</link>
			<guid>https://www.sthda.com/french/articles/19-latex/53-redigez-un-document-en-latex/</guid>
			<description><![CDATA[[page]Structure minimale[/page]<br />
<br />
<br />
LaTex se prononce latek et non latex. C'est un langage  permettant d'?crire des documents sans se pr?occuper de leur forme et il permet de produire des documents PDF. Cet article est une introduction ? LaTeX. Il contient les ?l?ments n?cessaires pour cr?er un article de haute qualit? avec LaTex. C'est une note de lecture des cours sur le <a href="http://www.siteduzero.com/informatique/tutoriels/redigez-des-documents-de-qualite-avec-latex">site du z?ro</a>.<br />
 <br />
Pour installer LaTex : <a href="http://latex-project.org/ftp.html">http://latex-project.org/ftp.html</a><br />
<br />
<h3 class="formatter-title">Structure d'un document simple</h3><br />
<br />
Pour un document en fran?ais :<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">article</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% Autres Type de documents : book, letter, report(rapport, stage, th?se)</span>
<span style="color: #2C922C; font-style: italic;">%Appel de packages</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>     
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% D?but du document</span>
 .... Votre texte .....
<span style="color: #2C922C; font-style: italic;">% portion de texte</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">recette</span><span style="color: #E02020; ">}</span>
....
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">recette</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Fin du document</span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Les commandes introduites par le package babel:</span></strong><br />
<br />
<< =  \og; >> = \fg;  Exposant : \up{}; Petites Majuscules = \bsc{Lamport}; 1er = 1\ier; 2e = 2\ieme;<br />
8? (ou n'importe quel autre chiffre) = \FrenchEnumerate{8}<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
J'?cris mon 3<span style="color: #800000; font-weight: normal;">\up</span><span style="color: #E02020; ">{</span>e<span style="color: #E02020; ">}</span> document avec <span style="color: #800000; font-weight: normal;">\og</span> <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5CLaTeX"><span style="color: #800000;">LaTeX</span></a><span style="color: #E02020; ">{}</span> <span style="color: #800000; font-weight: normal;">\fg</span>.
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5CLaTeX"><span style="color: #800000;">LaTeX</span></a><span style="color: #E02020; ">{}</span> est un langage cr?? par Leslie <span style="color: #800000; font-weight: normal;">\bsc</span><span style="color: #E02020; ">{</span>Lamport<span style="color: #E02020; ">}</span>.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Les caract?res sp?ciaux sont </span></strong>: $, &, %, #, -, _, {, }, ^, \<br />
Pour les utiliser, ils doivent ?tre pr?c?d?s d'un backslash (i.e \$).  Pour faire appara?tre un \ dans un texte, il faut utiliser la commande  \textbackslash{}.<br />
<br />
<span class="warning"><br />
Sous Mac OS : il est important que vous enregistriez vos documents en Latin-1<br />
Sous linux : Si la console inscrit ISO-8859, tout va bien. Si elle inscrit UTF-8, vous devrez taper \usepackage[utf8]{inputenc} ? la place de \usepackage[latin1]{inputenc} dans vos prochains documents.<br />
</span><br />
<br />
[page]Mise en page[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
Les ?l?ments de structure sont:<br />
<br />
<table class="formatter-table">
<tr class="formatter-table-row">
<td class="formatter-table-col">Partie</td>
 <td class="formatter-table-col">\part{nom de la partie}</td>
 </tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Chapitre</td>
<td class="formatter-table-col">\chapter{nom du chapitre}</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Section</td>
<td class="formatter-table-col">\section{nom de la section}</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Sous-section</td>
<td class="formatter-table-col">\subsection{nom de la sous section}</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Sous-sous-section</td>
<td class="formatter-table-col">\subsubsection{nom de la sous sous section}</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Paragraphe</td>
<td class="formatter-table-col">\paragraph{nom du paragraphe}</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Sous-paragraphe</td>
<td class="formatter-table-col">\subparagraph{nom du sous paragraphe}</td>
</tr>
</table><br />
<br />
<span class="notice">Notez que \chapter n'est pas disponible pour les classes de document article et letter.</span><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">report<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\part</span><span style="color: #E02020; ">{</span><span style="color: #00008B; font-weight: bold;">Partie</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cchapter"><span style="color: #800000;">chapter</span></a><span style="color: #E02020; ">{</span>premier chapitre<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cchapter"><span style="color: #800000;">chapter</span></a>{second chapitre</span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%Annexe</span>
<span style="color: #2C922C; font-style: italic;">% Pas besoin de changer de commande pour transformer un chapitre en annexe gr?ce ? appendix</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cappendix"><span style="color: #800000;">appendix</span></a>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cchapter"><span style="color: #800000;">chapter</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Un sch?ma<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cchapter"><span style="color: #800000;">chapter</span></a><span style="color: #E02020; ">{</span>Un article annexe<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Page de garde</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">book<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>   
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span>]{babel</span><span style="color: #E02020; ">}</span>    
&nbsp;
 <span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Page de garde</span>
 <span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctitle"><span style="color: #800000;">title</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Les Lapins<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cauthor"><span style="color: #800000;">author</span></a><span style="color: #E02020; ">{</span>John <span style="color: #800000; font-weight: normal;">\bsc</span><span style="color: #E02020; ">{</span>Doe<span style="color: #E02020; ">}}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdate"><span style="color: #800000;">date</span></a>{3 mai 2010</span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%fin page de garde</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%d?but du document</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cmaketitle"><span style="color: #800000;">maketitle</span></a> <span style="color: #2C922C; font-style: italic;">%Cr?ation de la page de garde</span>
.... Votre Texte .....
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Alignements du texte</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">flushright</span><span style="color: #E02020; ">}</span> VOTRE TEXTE ICI <span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">flushright</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Aligner le texte ? droite</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span> VOTRE TEXTE ICI <span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Centrer le texte</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">flushleft</span><span style="color: #E02020; ">}</span> VOTRE TEXTE ICI <span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">flushleft</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Aligner le texte ? gauche</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="notice">Le texte est justifi? par d?faut.</span><br />
<br />
<h3 class="formatter-title">Sauts</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #800000; font-weight: normal;">\newline</span> <span style="color: #2C922C; font-style: italic;">% Aller ? la ligne sans cr?er de nouveau paragraphe</span>
<span style="color: #E02020; ">\\</span> <span style="color: #2C922C; font-style: italic;">% idem, aller ? la ligne sans cr?er de nouveau paragraphe</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cnewpage"><span style="color: #800000;">newpage</span></a> <span style="color: #2C922C; font-style: italic;">% saut de page</span>
<span style="color: #800000; font-weight: normal;">\clearpage</span> <span style="color: #2C922C; font-style: italic;">% Changement de page apr?s gestion des flottants.</span>
<span style="color: #800000; font-weight: normal;">\cleardoublepage</span> <span style="color: #2C922C; font-style: italic;">% Idem, mais red?marre sur une page impaire.</span>
Un ?colier<span style="color: #E02020; ">\</span><span style="color: #800000; font-weight: normal;">\un</span> cahier<span style="color: #800000; font-weight: normal;">\newline</span> une r?gle<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cnewpage"><span style="color: #800000;">newpage</span></a> un bonbon
&nbsp;</pre></pre></div><br />
<br />
<span class="notice"><strong>Pour cr?er un paragraphe</strong>, sauter 2 lignes.</span><br />
<br />
<h3 class="formatter-title">La forme du document</h3><br />
<br />
La commande <strong><span style="color:blue;">\documentclass{} </span></strong>peut ?tre personnalis?e gr?ce ? des options contenues entre crochets et s?par?es par des virgules de la fa?on suivante : \documentclass[option1, option2, option3]{type}.<br />
<br />
<strong><span style="color:blue;">Les options peuvent ?tre :</span></strong><br />
<br />
<table class="formatter-table">
<tr class="formatter-table-row">
<th class="formatter-table-head">Description</th>
                <th class="formatter-table-head">Valeurs applicables</th>
                <th class="formatter-table-head">Valeurs par d?faut</th>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Format du papier</td>
<td class="formatter-table-col">a4paper, a5paper, letterpaper, b5paper?</td>
<td class="formatter-table-col">letterpaper</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Taille de la police principale</td>
<td class="formatter-table-col">10pt, 11pt, 12pt</td>
<td class="formatter-table-col">10pt</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Alignement des ?quations</td>
<td class="formatter-table-col">fleqn (? gauche)</td>
<td class="formatter-table-col">centr?es par d?faut</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Colonnes</td>
<td class="formatter-table-col">onecolumn, twocolumn</td>
<td class="formatter-table-col">onecolumn</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Premi?re page des chapitres</td>
<td class="formatter-table-col">openany, openright</td>
<td class="formatter-table-col">openright</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Recto verso</td>
<td class="formatter-table-col">oneside, twoside</td>
<td class="formatter-table-col">article et report : oneside, book : twoside</td>
</tr>
</table><br />
<br />
<strong><span style="color:blue;">Exemple</span></strong><br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">twocolumn, 12pt</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">book</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Rappel : <strong><span style="color:blue;">Les types de documents </span></strong>: <strong>article</strong> (article scientifique), <strong>book</strong> (livre), <strong>letter</strong>(lettre), <strong>report</strong> (rapport, stage, th?se).<br />
</span><br />
<br />
<h3 class="formatter-title">Marges</h3><br />
<br />
Il suffit d'utiliser le package geometry dans lequel nous sp?cifierons les tailles des marges en haut, en bas, ? gauche puis ? droite.<br />
La syntaxe est la suivante : <br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;"><span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">top=2cm, bottom=2cm, left=2cm, right=2cm</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">geometry</span><span style="color: #E02020; ">}</span></pre></pre></div><br />
<br />
<h3 class="formatter-title">Interlignes</h3><br />
<br />
<span style="color:blue;">Afin d'obtenir des interlignes personnalis?s</span>, il faut utiliser le <strong><span style="color:blue;">package setspace </span></strong>ainsi que les commandes <strong><span style="color:blue;">\onehalfspacing </span></strong>et <strong><span style="color:blue;">\doublespacing</span></strong> dans le pr?ambule, qui permettent d'obtenir dans tout le document un interligne respectivement 1,5 et 2 fois plus grand que l'interligne habituel.<br />
<br />
<span class="notice"><br />
Pour ne changer les interlignes que dans des petits morceaux de votre composition, les environnements onehalfspace et doublespace sont adapt?s. <strong>Exemple :</strong><br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">setspace<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">onehalfspace</span><span style="color: #E02020; ">}</span>
Un autre paragraphe.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">onehalfspace</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
</span><br />
<br />
<br />
<h3 class="formatter-title">Les listes</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
 <span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span>{concordance=TRUE</span><span style="color: #E02020; ">}</span>
 <span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Liste ? puce</span>
 <span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a>*<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Les listes ? puce <span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">itemize</span></span><span style="color: #E02020; ">}</span> 
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Citem"><span style="color: #800000;">item</span></a> Un canard.
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Citem"><span style="color: #800000;">item</span></a> Un mammouth.
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Citem"><span style="color: #800000;">item</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">*</span><span style="color: #E02020; ">]</span> Une pintade. <span style="color: #2C922C; font-style: italic;">% En pla?ant un * entre crochets apr?s \item, j'ai transform? la puce en *</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">itemize</span></span><span style="color: #E02020; ">}</span>
 <span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Liste num?rot?e</span>
 <span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a>*<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Listes num?rot?es<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">enumerate</span><span style="color: #E02020; ">}</span> 
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Citem"><span style="color: #800000;">item</span></a> Un canard.
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Citem"><span style="color: #800000;">item</span></a> Un mammouth.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">enumerate</span></span><span style="color: #E02020; ">}</span>
 <span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Liste de description</span>
 <span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a>*<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Listes de description<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">description</span></span><span style="color: #E02020; ">}</span><span style="color: #2C922C; font-style: italic;">%Liste de description</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Citem"><span style="color: #800000;">item</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">Un canard :</span><span style="color: #E02020; ">]</span> bestiole qui fait coin.
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Citem"><span style="color: #800000;">item</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">Un poulpe :</span><span style="color: #E02020; ">]</span> bestiole qui fait bloub.
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Citem"><span style="color: #800000;">item</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">Un ornithorynque :</span><span style="color: #E02020; ">]</span> bestiole qui fait rire.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">description</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:400px"><img src="https://www.sthda.com/french/french/upload/latex_liste.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Polices</h3><br />
<br />
 <h4 class="formatter-title">Graisse, style, taille</h4> <br />
<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a>{soul</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Pour les soulignement</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a>*<span style="color: #E02020; ">{</span>Graisse, soulignement<span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\normalfont</span>{Un lapin, </span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Normal</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctextbf"><span style="color: #800000;">textbf</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">un lapin, </span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Gras</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctextit"><span style="color: #800000;">textit</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">un lapin, </span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Italique</span>
<span style="color: #800000; font-weight: normal;">\textsc</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">un lapin, </span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Majuscule</span>
Un canard <span style="color: #800000; font-weight: normal;">\up</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">un lapin</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Exposant</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cfbox"><span style="color: #800000;">fbox</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">un lapin</span><span style="color: #E02020; ">}</span>, <span style="color: #2C922C; font-style: italic;">%Encadrer</span>
<span style="color: #800000; font-weight: normal;">\ul</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">un lapin</span><span style="color: #E02020; ">}</span>, <span style="color: #2C922C; font-style: italic;">%Soulignement, (Package soul)</span>
<span style="color: #800000; font-weight: normal;">\st</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">un lapin</span><span style="color: #E02020; ">}</span>, <span style="color: #2C922C; font-style: italic;">%Barrer</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a>*<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Taille<span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\scriptsize</span>{Maman</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%tr?s tr?s p?tite</span>
<span style="color: #800000; font-weight: normal;">\footnotesize</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Maman</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%tr?s p?tite</span>
<span style="color: #800000; font-weight: normal;">\small</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Maman</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Petite</span>
<span style="color: #800000; font-weight: normal;">\large</span> <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Maman</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%L?g?rement plus grande que la normale</span>
<span style="color: #800000; font-weight: normal;">\Large</span> <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Maman</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Grande</span>
<span style="color: #800000; font-weight: normal;">\LARGE</span> <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Maman</span><span style="color: #E02020; ">}</span><span style="color: #2C922C; font-style: italic;">% Tr?s Grande</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chuge"><span style="color: #800000;">huge</span></a> <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Maman</span><span style="color: #E02020; ">}</span><span style="color: #2C922C; font-style: italic;">% Tr?s Tr?s Grande</span>
<span style="color: #800000; font-weight: normal;">\Huge</span> <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Maman</span><span style="color: #E02020; ">}</span><span style="color: #2C922C; font-style: italic;">% Enorme</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:350px"><img src="https://www.sthda.com/french/french/upload/latex_police_taille_style.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Couleurs</h4> <br />
<br />
Pour la coloration du texte, nous utiliserons le <strong><span style="color:blue;">package color</span></strong>. <strong><span style="color:blue;">Ce package propose par d?faut huit couleurs </span></strong>(black, white, red, green, blue, yellow, magenta et cyan), que vous pourrez utiliser pour colorer du texte via la commande suivante :<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctextcolor"><span style="color: #800000;">textcolor</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">green}{texte en couleur</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
Pour cr?er de nouvelles couleurs, une commande est disponible : \definecolor<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdefinecolor"><span style="color: #800000;">definecolor</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">le nom de couleur choisi}{RGB}{taux de rouge entre 0 et 255,taux de vert,taux de bleu</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Exemple :</span></strong><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span>color<span style="color: #E02020; ">}</span> 
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdefinecolor"><span style="color: #800000;">definecolor</span></a><span style="color: #E02020; ">{</span>violet<span style="color: #E02020; ">}{</span>RGB<span style="color: #E02020; ">}{</span>134,64,164<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctextcolor"><span style="color: #800000;">textcolor</span></a><span style="color: #E02020; ">{</span>violet<span style="color: #E02020; ">}{</span>Maman<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
[page]Ins?rer du code, URL, Texte encadr?, notes de bas de pages, R?f?rences internes[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Ins?rer du code</h3><br />
<br />
Trois m?thodes disponibles :<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Ins?rer du code dans un paragraphe</span>
<span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++++</span>
Etant d?butant en LaTex, j'ai appris ? utiliser la commande <span style="color: #800000; font-weight: normal;">\verb</span>|<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"></span><span style="color: #E02020; ">}</span>|
<span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Ins?rer un gros volume de code</span>
<span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++++</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">verbatim</span><span style="color: #E02020; ">}</span>
....VOTRE CODE ICI...
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">verbatim</span></span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Ins?rer un gros volume de code avec coloration syntaxique</span>
<span style="color: #2C922C; font-style: italic;">%(Explication plus bas dans le document)</span>
<span style="color: #2C922C; font-style: italic;">%++++++++++++++++++++++++++++++</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">lstlisting</span><span style="color: #E02020; ">}</span>
....VOTRE CODE ICI...
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">lstlisting</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Noubliez pas d'inclure dans l'ent?te du document les packages <strong><span style="text-decoration: underline;">verbatim</span></strong> ou <strong><span style="text-decoration: underline;">lstlisting</span></strong> en fonction de la commande utilis?e.<br />
</span><br />
<br />
<strong><span style="color:blue;">L'environnement lstlisting</span></strong><br />
L'environnement lstlisting permet de mettre en forme de fa?on color?e et d'utiliser de nombreuses options pour afficher du code.<br />
<br />
Appeler le <strong>package listings</strong> dans l'en-t?te du document<br />
Pour parametrer l'affichage du code, utilisez la commande <strong>\lstset </strong>qui se place avant \begin{document} et poss?de un grand nombre d'arguments param?trables.<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #800000; font-weight: normal;">\lstset</span><span style="color: #E02020; ">{</span> <span style="color: #2C922C; font-style: italic;">%</span>
language=nom_du_langage,        <span style="color: #2C922C; font-style: italic;">% choix du langage</span>
basicstyle=<span style="color: #800000; font-weight: normal;">\footnotesize</span>,       <span style="color: #2C922C; font-style: italic;">% taille de la police du code</span>
numbers=left,                   <span style="color: #2C922C; font-style: italic;">% placer le num?ro de chaque ligne ? gauche (left)</span>
numbers=right,                  <span style="color: #2C922C; font-style: italic;">% placer le num?ro de chaque ligne ? droite (right)</span>
numberstyle=<span style="color: #800000; font-weight: normal;">\normalsize</span>,        <span style="color: #2C922C; font-style: italic;">% taille de la police des num?ros</span>
numbersep=7pt,                  <span style="color: #2C922C; font-style: italic;">% distance entre le code et sa num?rotation</span>
backgroundcolor=<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccolor"><span style="color: #800000;">color</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">white</span><span style="color: #E02020; ">}</span>,  <span style="color: #2C922C; font-style: italic;">% couleur du fond</span>
<span style="color: #2C922C; font-style: italic;">% Possibilit? d'utilisation du package color</span>
<span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><a href="http://en.wikibooks.org/wiki/LaTeX/Packages/Listings">La page de Wikibooks consacr?e au package listings est accessible ici</a></span><br />
<br />
Le code ? afficher s'ins?re dans votre document via l'environnement<strong> lstlisting</strong>.<br />
<br />
Ci-dessous, un petit exemple du traitement d'un code C avec lstlisting.<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span>listings, color<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdefinecolor"><span style="color: #800000;">definecolor</span></a>{gray}{RGB}{234, 244, 243</span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%Param?tre d'affichage du code ? ins?rer</span>
<span style="color: #800000; font-weight: normal;">\lstset</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">
language=C,
basicstyle=<span style="color: #800000; font-weight: normal;">\footnotesize</span>,
numbers=left,
numberstyle=<span style="color: #800000; font-weight: normal;">\normalsize</span>,
numbersep=7pt,
keywordstyle=<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccolor"><span style="color: #800000;">color</span></a><span style="color: #E02020; ">{</span>blue<span style="color: #E02020; ">}</span>,
backgroundcolor=<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccolor"><span style="color: #800000;">color</span></a><span style="color: #E02020; ">{</span>gray<span style="color: #E02020; ">}</span>, 
<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span>{concordance=TRUE</span><span style="color: #E02020; ">}</span>
&nbsp;
 <span style="color: #2C922C; font-style: italic;">%code ? ins?rer dans le document</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">lstlisting</span><span style="color: #E02020; ">}</span>
if (age == 2)
<span style="color: #E02020; ">{</span>
  printf("Salut bebe !");
<span style="color: #E02020; ">}</span>
else if (age == 6)
<span style="color: #E02020; ">{</span>
  printf("Salut gamin !");
<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">lstlisting</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:170px"><img src="https://www.sthda.com/french/french/upload/latex_insertion_code.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">URL</h3><br />
Pour ins?rer une URL, il vous suffit d'utiliser le package url ainsi que la commande \url{adresse}<br />
<br />
<br />
<h3 class="formatter-title">Texte encadr?</h3><br />
<br />
<strong><span style="color:blue;">La commande \fbox</span></strong>, permettant d'encadrer des portions de texte. Deux param?tres sont ? indiquer: l'?cart entre le texte et la bordure ainsi que l'?paisseur de cette derni?re.<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csetlength"><span style="color: #800000;">setlength</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\fboxsep</span>}{8mm</span><span style="color: #E02020; ">}</span><span style="color: #2C922C; font-style: italic;">% d?finir l'?cart</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csetlength"><span style="color: #800000;">setlength</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\fboxrule</span>}{2mm</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% d?finir l'?paisseur du trait</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cfbox"><span style="color: #800000;">fbox</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Un lapin</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:170px"><img src="https://www.sthda.com/french/french/upload/latex_texte_encadre.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">L'environnement minipage</span></strong> permet d'encadrer un paragraphe. Deux param?tres nous int?ressent : la largeur du box et son positionnement par rapport au texte l'entourant. Le positionnement peut ?tre <strong>c</strong> (pour center),<strong> t</strong>(pour top), <strong>b</strong>(pour bottom).<br />
<br />
<strong>Exemple :</strong><br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cfbox"><span style="color: #800000;">fbox</span></a><span style="color: #E02020; ">{</span> <span style="color: #2C922C; font-style: italic;">%fbox est utilis? pour voir les bords de la minipage</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">minipage</span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">c</span><span style="color: #E02020; ">]{</span>8cm<span style="color: #E02020; ">}</span>
 It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">minipage</span>}
</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:200px"><img src="https://www.sthda.com/french/french/upload/latex_encadre_paragraphe.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Les notes de bas de page</h3><br />
<br />
<strong><span style="color:blue;">La commande \footnote</span></strong> : \footnote{Texte de la note.}<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
un canard<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cfootnote"><span style="color: #800000;">footnote</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">bestiole qui fait coin<span style="color: #E02020; ">}</span>
un ornithorynque<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cfootnote"><span style="color: #800000;">footnote</span></a><span style="color: #E02020; ">{</span>bestiole qui fait rire<span style="color: #E02020; ">}</span>
un ours<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cfootnote"><span style="color: #800000;">footnote</span></a>{bestiole qui fait mal</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:200px"><img src="https://www.sthda.com/french/french/upload/latex_note_de_bas_de_page.png"/></div></center>
<!-- END HTML --><br />
<br />
<span class="warning">Voir aussi \footnotemark</span><br />
<br />
<br />
<h3 class="formatter-title">Les r?f?rences internes</h3><br />
<br />
Trois commandes sont ? conna?tre. La commande <strong><span style="color:blue;">\label{nom_choisi}</span></strong> sert ? marquer un endroit, et les commandes <strong><span style="color:blue;">ref{nom_choisi}</span></strong> et <strong><span style="color:blue;">{\pageref{nom_choisi}} </span></strong>vous permettent d'appeler le num?ro de page ou la r?f?rence de l'?l?ment marqu? dans une autre zone de votre document.<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:700px; height:200px"><img src="https://www.sthda.com/french/french/upload/latex_ref_interne.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
[page]Insertion d'images et de figures[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<span class="notice"><br />
Chargez le <strong><span style="color:blue;">package graphix </span></strong>via la commande \usepackage{graphicx} ? chaque fois que vous aurez ? manipuler des images.<br />
</span><br />
<br />
<h3 class="formatter-title">Insertion simple</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">chemin de l'image</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% chemin absolu ou r?latif</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">width=200</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">chemin de l'image.png<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">height=200</span><span style="color: #E02020; ">]{</span>chemin de l'image.png<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">height=200, width=600</span><span style="color: #E02020; ">]{</span>chemin de l'image.png<span style="color: #E02020; ">}</span> 
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">scale=1.5</span>]{chemin de l'image.png</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%l'image est agrandie 1.5 fois de mani?re proportionnelle</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Rotation d'une image</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">angle=45</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">poulpy.png</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% Poulpy en biais</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Ins?rer une image dans un paragraphe</h3><br />
L'image devra faire 4 cm de large, occuper 8 lignes et se trouver ? droite du paragraphe.<br />
<br />
La solution de l'exercice se trouve ci-dessous, illustr?e avec la figure suivante.<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">12pt</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">report<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span>wrapfig<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span>graphicx<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">wrapfigure</span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">8</span><span style="color: #E02020; ">]{</span>r<span style="color: #E02020; ">}{</span>4cm<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">width=4cm</span><span style="color: #E02020; ">]{</span>poulpy.png<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">wrapfigure</span><span style="color: #E02020; ">}</span>
Gros paragraphe.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:700px; height:350px"><img src="https://www.sthda.com/french/french/upload/latex_image_dans_paragraphe.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Image flottante</h3><br />
<br />
Ceci permet ? LaTex de g?rer automatiquement l'insertion des images. <br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}</span><span style="color: #2C922C; font-style: italic;">% cr?ation d'une image flottante</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">center</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% On centre l'image</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">poulpy.png<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="notice"><br />
Il est possible de sp?cifier ? l'environnement figure, votre pr?f?rence en termes de placement. La commande est la suivante : <strong>\begin{figure}[option]</strong><br />
</span><br />
<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
Les options de placement d'une figure:
- Options non s?par?es par des virgules
- Le "!" est utilis? pour insiter
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">b</span><span style="color: #E02020; ">]</span> <span style="color: #2C922C; font-style: italic;">%flottant en bas.</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">t</span><span style="color: #E02020; ">]</span> <span style="color: #2C922C; font-style: italic;">%flottant en haut.</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">p</span><span style="color: #E02020; ">]</span> <span style="color: #2C922C; font-style: italic;">%flottant sur une page ne comportant que des flottants.</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">!b</span><span style="color: #E02020; ">]</span> <span style="color: #2C922C; font-style: italic;">%flottant en bas (avec insistance).</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">bt</span><span style="color: #E02020; ">]</span> <span style="color: #2C922C; font-style: italic;">%nous voulons le flottant en bas, ou en haut s'il ne peut pas?tre en bas.</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">h</span><span style="color: #E02020; ">]</span> <span style="color: #2C922C; font-style: italic;">%nous voulons le flottant ici.(? l'endroit o? la commande est tap?e)</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">H</span><span style="color: #E02020; ">]</span> <span style="color: #2C922C; font-style: italic;">%nous voulons le flottant ICI !</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">hb</span><span style="color: #E02020; ">]</span> <span style="color: #2C922C; font-style: italic;">%nous voulons le flottant ici, ou en bas si cela n'est paspossible.</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Les l?gendes</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">{</span>poulpy.png<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>Poulpy est multicolore<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clabel"><span style="color: #800000;">label</span></a><span style="color: #E02020; ">{</span>Poulpy est multicolore<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:340px"><img src="https://www.sthda.com/french/french/upload/latex_legende_figure.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Sauts de page</h3><br />
<br />
On peut faire un saut de page dans un document LaTex gr?ce ? la commande <em><span style="color:blue;">newpage</span></em>. Avec les flottants, deux nouvelles commandes apparaissent :<br />
<br />
    \clearpage, qui r?alise un saut de page tout en imposant ? LaTeX de mettre tous les flottants en page (il les traitera tous, et produira des pages remplies par les flottants non trait?s) ;<br />
<br />
    \cleardoublepage, qui a le m?me effet, si ce n'est qu'il reprend la nouvelle page sur une page impaire.<br />
<br />
<span class="warning">Comprenez bien l'utilit? de ces commandes. Si vous ?crivez un rapport en deux grandes parties, il est primordial qu'aucune image de la premi?re partie ne se retrouve dans la seconde ? cause d'un choix inopportun de LaTeX. Ces deux commandes s'utilisent exactement de la m?me mani?re que ewpage.<br />
</span><br />
<br />
[page]Les tableaux[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
Nous devons d?cider de l'alignement des cellules dans chaque colonne. Elles peuvent ?tre?<br />
    ? droite (option r) ;<br />
    ? gauche (option l) ;<br />
    centr?es (option c).<br />
<br />
<h3 class="formatter-title">Structure type</h3><br />
<br />
Nous allons cr?er un tableau contenant des colonnes centr?es.<br />
<br />
Plusieurs exemples sont montr?s dans le code ci-dessous et le r?sultat est affich? sur la figure apr?s.<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">report<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span>{concordance=TRUE</span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">% Tableau sans bordure</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsubsection"><span style="color: #800000;">subsubsection</span></a>*<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Tableau sans bordure :<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>cc<span style="color: #E02020; ">}</span>
1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">\\</span>
3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">\\</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span></span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%Tableau avec bordure</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsubsection"><span style="color: #800000;">subsubsection</span></a>*<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Tableau avec bordures :<span style="color: #E02020; ">}</span>
Il faut placer la commande <span style="color: #800000; font-weight: normal;">\verb</span>|<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>| entre deux lignes cons?cutives, et plus g?n?ralement partout o? vous souhaitez obtenir une ligne horizontale (dans un tableau).<span style="color: #E02020; ">\\</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>cc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span></span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%bordure des colonnes visibles</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsection"><span style="color: #800000;">subsection</span></a>*<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Marquer la s?paration entre deux colonnes cons?cutives<span style="color: #E02020; ">}</span>
Pour marquer la s?paration entre deux colonnes cons?cutives par une bordure verticale, il faut ins?rer le caract?re " | ". 
Ici, <span style="color: #E02020; ">{</span>cc<span style="color: #E02020; ">}</span> devient <span style="color: #E02020; ">{</span>|c|c|<span style="color: #E02020; ">}</span>.<span style="color: #E02020; ">\\</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>|c|c|<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span></span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%Un grand tableau</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsection"><span style="color: #800000;">subsection</span></a>*<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Un grand tableau<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>|c|c|c|c|c|c|c|c|c|c|c|<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
Multipli? par <span style="color: #E02020; ">&</span> 1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">&</span> 3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">&</span> 5 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 7 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 9 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1 <span style="color: #E02020; ">&</span> 1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">&</span> 3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">&</span> 5 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 7 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 9 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
2 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">&</span> 12 <span style="color: #E02020; ">&</span> 14 <span style="color: #E02020; ">&</span> 16 <span style="color: #E02020; ">&</span> 18 <span style="color: #E02020; ">&</span> 20 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
3 <span style="color: #E02020; ">&</span> 3 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 9 <span style="color: #E02020; ">&</span> 12 <span style="color: #E02020; ">&</span> 15 <span style="color: #E02020; ">&</span> 18 <span style="color: #E02020; ">&</span> 21 <span style="color: #E02020; ">&</span> 24 <span style="color: #E02020; ">&</span> 27 <span style="color: #E02020; ">&</span> 30 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
4 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 12 <span style="color: #E02020; ">&</span> 16 <span style="color: #E02020; ">&</span> 20 <span style="color: #E02020; ">&</span> 24 <span style="color: #E02020; ">&</span> 28 <span style="color: #E02020; ">&</span> 32 <span style="color: #E02020; ">&</span> 36 <span style="color: #E02020; ">&</span> 40 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
5 <span style="color: #E02020; ">&</span> 5 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">&</span> 15 <span style="color: #E02020; ">&</span> 20 <span style="color: #E02020; ">&</span> 25 <span style="color: #E02020; ">&</span> 30 <span style="color: #E02020; ">&</span> 35 <span style="color: #E02020; ">&</span> 40 <span style="color: #E02020; ">&</span> 45 <span style="color: #E02020; ">&</span> 50 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
6 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 12 <span style="color: #E02020; ">&</span> 18 <span style="color: #E02020; ">&</span> 24 <span style="color: #E02020; ">&</span> 30 <span style="color: #E02020; ">&</span> 36 <span style="color: #E02020; ">&</span> 42 <span style="color: #E02020; ">&</span> 48 <span style="color: #E02020; ">&</span> 54 <span style="color: #E02020; ">&</span> 60 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
7 <span style="color: #E02020; ">&</span> 7 <span style="color: #E02020; ">&</span> 14 <span style="color: #E02020; ">&</span> 21 <span style="color: #E02020; ">&</span> 28 <span style="color: #E02020; ">&</span> 35 <span style="color: #E02020; ">&</span> 42 <span style="color: #E02020; ">&</span> 49 <span style="color: #E02020; ">&</span> 56 <span style="color: #E02020; ">&</span> 63 <span style="color: #E02020; ">&</span> 70 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
8 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 16 <span style="color: #E02020; ">&</span> 24 <span style="color: #E02020; ">&</span> 32 <span style="color: #E02020; ">&</span> 40 <span style="color: #E02020; ">&</span> 48 <span style="color: #E02020; ">&</span> 56 <span style="color: #E02020; ">&</span> 64 <span style="color: #E02020; ">&</span> 72 <span style="color: #E02020; ">&</span> 80 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
9 <span style="color: #E02020; ">&</span> 9 <span style="color: #E02020; ">&</span> 18 <span style="color: #E02020; ">&</span> 27 <span style="color: #E02020; ">&</span> 36 <span style="color: #E02020; ">&</span> 45 <span style="color: #E02020; ">&</span> 54 <span style="color: #E02020; ">&</span> 63 <span style="color: #E02020; ">&</span> 72 <span style="color: #E02020; ">&</span> 81 <span style="color: #E02020; ">&</span> 90 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
10 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">&</span> 20 <span style="color: #E02020; ">&</span> 30 <span style="color: #E02020; ">&</span> 40 <span style="color: #E02020; ">&</span> 50 <span style="color: #E02020; ">&</span> 60 <span style="color: #E02020; ">&</span> 70 <span style="color: #E02020; ">&</span> 80 <span style="color: #E02020; ">&</span> 90 <span style="color: #E02020; ">&</span> 100 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:640px"><img src="https://www.sthda.com/french/french/upload/latex_tableaux.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Fusion des cellules</h3><br />
<br />
<strong><span style="color:blue;">Fusion des colonnes</span></strong><br />
<strong>La commande :</strong><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #800000; font-weight: normal;">\multicolumn</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">nombre de colonnes fusionn?es}{c, l ou r accompagn? des bordures ?ventuelles}{le texte de la cellule</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Fusion des lignes</span></strong><br />
<br />
Il faut utiliser la commande <strong>\multirow</strong> contenu dans le package du m?me nom. Elle est d?pendante de trois param?tres (L'un des param?tres est rempla?able par une ?toile.) :<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #800000; font-weight: normal;">\multirow</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">nombre de lignes fusionn?es<span style="color: #E02020; ">}{</span>taille de la colonne en cm<span style="color: #E02020; ">}{</span>votre texte<span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\multirow</span>{nombre de lignes fusionn?es}*{votre texte</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="notice"><br />
Notez que la commande \cline a ?t? introduite. Elle vous permet selon vos souhaits de ne mettre une ligne horizontale qu'entre deux colonnes choisies par vous (Les colonnes sont num?rot?es de la gauche vers la droite.).<br />
</span><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">report<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span>]{babel</span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%Package multirow</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">multirow<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsection"><span style="color: #800000;">subsection</span></a>*{Fusion de colonnes</span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%+++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Fusion de colonnes</span>
<span style="color: #2C922C; font-style: italic;">%+++++++++++++++++++++++</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>|c|c|c|c|c|<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1 <span style="color: #E02020; ">&</span> <span style="color: #800000; font-weight: normal;">\multicolumn</span><span style="color: #E02020; ">{</span>2<span style="color: #E02020; ">}{</span>c|<span style="color: #E02020; ">}{</span>2<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">&</span> 3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #800000; font-weight: normal;">\multicolumn</span><span style="color: #E02020; ">{</span>2<span style="color: #E02020; ">}{</span>|c|<span style="color: #E02020; ">}{</span>5<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 7 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
9 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">&</span> <span style="color: #800000; font-weight: normal;">\multicolumn</span><span style="color: #E02020; ">{</span>3<span style="color: #E02020; ">}{</span>c|<span style="color: #E02020; ">}{</span>11<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsection"><span style="color: #800000;">subsection</span></a>*{Fusion de lignes</span><span style="color: #E02020; ">}</span>
<span style="color: #2C922C; font-style: italic;">%+++++++++++++++++++++++</span>
<span style="color: #2C922C; font-style: italic;">%Fusion de lignes</span>
<span style="color: #2C922C; font-style: italic;">%+++++++++++++++++++++++</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>|l|c|c|c|c|<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1 <span style="color: #E02020; ">&</span> <span style="color: #800000; font-weight: normal;">\multicolumn</span><span style="color: #E02020; ">{</span>2<span style="color: #E02020; ">}{</span>c|<span style="color: #E02020; ">}{</span>2<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">&</span> 3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #800000; font-weight: normal;">\multicolumn</span><span style="color: #E02020; ">{</span>2<span style="color: #E02020; ">}{</span>|l|<span style="color: #E02020; ">}{</span>5<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 7 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
9 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">&</span> <span style="color: #800000; font-weight: normal;">\multicolumn</span><span style="color: #E02020; ">{</span>3<span style="color: #E02020; ">}{</span>c|<span style="color: #E02020; ">}{</span>11<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #800000; font-weight: normal;">\multirow</span><span style="color: #E02020; ">{</span>2<span style="color: #E02020; ">}{</span>1cm<span style="color: #E02020; ">}{</span>12<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">&</span> 13 <span style="color: #E02020; ">&</span> 14 <span style="color: #E02020; ">&</span> 15 <span style="color: #E02020; ">&</span> 16 <span style="color: #E02020; ">\\</span>
<span style="color: #800000; font-weight: normal;">\cline</span><span style="color: #E02020; ">{</span>2-5<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">&</span> 17 <span style="color: #E02020; ">&</span> 18 <span style="color: #E02020; ">&</span> 19 <span style="color: #E02020; ">&</span> 20 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
21 <span style="color: #E02020; ">&</span> 22 <span style="color: #E02020; ">&</span> <span style="color: #800000; font-weight: normal;">\multirow</span><span style="color: #E02020; ">{</span>2<span style="color: #E02020; ">}</span>*<span style="color: #E02020; ">{</span>23<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">&</span> 24 <span style="color: #E02020; ">&</span> 25 <span style="color: #E02020; ">\\</span>
<span style="color: #800000; font-weight: normal;">\cline</span><span style="color: #E02020; ">{</span>1-2<span style="color: #E02020; ">}</span> <span style="color: #800000; font-weight: normal;">\cline</span><span style="color: #E02020; ">{</span>4-5<span style="color: #E02020; ">}</span>
26 <span style="color: #E02020; ">&</span> 27 <span style="color: #E02020; ">&</span> <span style="color: #E02020; ">&</span> 28 <span style="color: #E02020; ">&</span> 29 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:420px"><img src="https://www.sthda.com/french/french/upload/latex_fusion_de_cellules.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Largeur des colonnes</h3><br />
<br />
<strong><span style="color:blue;">La commande :</span></strong><br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">p<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">largeur de la colonne en centim?tres</span><span style="color: #E02020; ">}</span></pre></pre></div><br />
<br />
<strong><span style="color:blue;">Exemple :</span></strong><br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>|p<span style="color: #E02020; ">{</span>1cm<span style="color: #E02020; ">}</span>|p<span style="color: #E02020; ">{</span>2cm<span style="color: #E02020; ">}</span>|p<span style="color: #E02020; ">{</span>3cm<span style="color: #E02020; ">}</span>|p<span style="color: #E02020; ">{</span>4cm<span style="color: #E02020; ">}</span>|<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1cm <span style="color: #E02020; ">&</span> 2cm <span style="color: #E02020; ">&</span> 3cm <span style="color: #E02020; ">&</span> 4cm <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:100px"><img src="https://www.sthda.com/french/french/upload/latex_tableaux_largeur_colonne.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Cr?er une slashbox</h3><br />
<br />
<span class="success">Le package slashbox permet d'utiliser la commande \backslashbox{Texte dessous}{Texte dessus}</span><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>|c|p<span style="color: #E02020; ">{</span>1cm<span style="color: #E02020; ">}</span>|p<span style="color: #E02020; ">{</span>2cm<span style="color: #E02020; ">}</span>|<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #800000; font-weight: normal;">\backslashbox</span><span style="color: #E02020; ">{</span>Patate<span style="color: #E02020; ">}{</span>Carotte<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">&</span> 1cm <span style="color: #E02020; ">&</span> 2cm <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:80px"><img src="https://www.sthda.com/french/french/upload/latex_tableaux_slashbox.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Colorer des cellules</h3><br />
<br />
<span class="warning">Deux packages sont ? utiliser : color et colortbl.</span><br />
<br />
<strong>Les commandes sont les suivantes :</strong><br />
<br />
   <strong> \columncolor{couleur}</strong> pour colorer les colonnes ;<br />
<br />
    <strong>\rowcolor{couleur}</strong> pour colorer les lignes ; pour colorer les lignes ;<br />
<br />
    <strong>\cellcolor{couleur}</strong> pour colorer les cellules.<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">report<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span>color<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span>colortbl<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>| ><span style="color: #E02020; ">{</span><span style="color: #800000; font-weight: normal;">\columncolor</span><span style="color: #E02020; ">{</span>yellow<span style="color: #E02020; ">}}</span>c|c|c|c|c|c|c|c|c|c|c|<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #800000; font-weight: normal;">\rowcolor</span><span style="color: #E02020; ">{</span>yellow<span style="color: #E02020; ">}</span>Multipli? par <span style="color: #E02020; ">&</span> 1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">&</span> 3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">&</span> 5 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 7 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 9 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1 <span style="color: #E02020; ">&</span> 1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">&</span> 3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">&</span> 5 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 7 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 9 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
2 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">&</span> 12 <span style="color: #E02020; ">&</span> 14 <span style="color: #E02020; ">&</span> 16 <span style="color: #E02020; ">&</span> 18 <span style="color: #E02020; ">&</span> 20 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
3 <span style="color: #E02020; ">&</span> 3 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 9 <span style="color: #E02020; ">&</span> 12 <span style="color: #E02020; ">&</span> 15 <span style="color: #E02020; ">&</span> 18 <span style="color: #E02020; ">&</span> 21 <span style="color: #E02020; ">&</span> 24 <span style="color: #E02020; ">&</span> 27 <span style="color: #E02020; ">&</span> 30 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
4 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">&</span> 8 <span style="color: #E02020; ">&</span> 12 <span style="color: #E02020; ">&</span> 16 <span style="color: #E02020; ">&</span> 20 <span style="color: #E02020; ">&</span> 24 <span style="color: #E02020; ">&</span> 28 <span style="color: #E02020; ">&</span> 32 <span style="color: #E02020; ">&</span> 36 <span style="color: #E02020; ">&</span> 40 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
5 <span style="color: #E02020; ">&</span> 5 <span style="color: #E02020; ">&</span> 10 <span style="color: #E02020; ">&</span> 15 <span style="color: #E02020; ">&</span> 20 <span style="color: #E02020; ">&</span> 25 <span style="color: #E02020; ">&</span> 30 <span style="color: #E02020; ">&</span> 35 <span style="color: #E02020; ">&</span> 40 <span style="color: #E02020; ">&</span> 45 <span style="color: #E02020; ">&</span> 50 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
6 <span style="color: #E02020; ">&</span> 6 <span style="color: #E02020; ">&</span> 12 <span style="color: #E02020; ">&</span> 18 <span style="color: #E02020; ">&</span> 24 <span style="color: #E02020; ">&</span> 30 <span style="color: #E02020; ">&</span> 36 <span style="color: #E02020; ">&</span> 42 <span style="color: #E02020; ">&</span> 48 <span style="color: #E02020; ">&</span> 54 <span style="color: #E02020; ">&</span> 60 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:170px"><img src="https://www.sthda.com/french/french/upload/latex_tableau_colore_cellules.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<span class="notice"><br />
Notez que pour pouvoir agir sur les colonnes, il vous faudra utiliser >{votre commande ou votre \begin{..\ }} avant l'instruction de cr?ation de colonne (l, r, c ou \p{}) et >{votre commande ou votre \end{..} } juste apr?s si vous le souhaitez.<br />
</span><br />
<br />
<h3 class="formatter-title">Un tableau flottant</h3><br />
<br />
Pour rendre un tableau flottant, et laisser LaTeX g?rer sa position, il faut l'entourer de l'environnement table<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">table</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}</span>
Votre tableau
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>votre l?gende<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clabel"><span style="color: #800000;">label</span></a><span style="color: #E02020; ">{</span>votre r?f?rence<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">table</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
[page]Table des mati?res[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<span class="notice">Il vous suffit d'ins?rer la commande <strong>\tableofcontents </strong>? l'endroit o? vous souhaitez afficher une table des mati?res dans votre document.</span><br />
<br />
<h3 class="formatter-title">Table des mati?res simple</h3><br />
<br />
<span class="warning"><br />
La seule subtilit? r?side dans le fait qu'il faille compiler deux fois. La premi?re permet ? LaTeX de comprendre la structure du document et de lister les titres. La seconde permet la mise en forme de la table, avec les num?ros de pages.<br />
</span><br />
<br />
<strong><span style="color:blue;">Exemple:</span></strong><br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">book<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctableofcontents"><span style="color: #800000;">tableofcontents</span></a>
<span style="color: #800000; font-weight: normal;">\part</span><span style="color: #E02020; ">{</span><span style="color: #00008B; font-weight: bold;">Partie 1</span><span style="color: #E02020; ">}</span>
    <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cchapter"><span style="color: #800000;">chapter</span></a><span style="color: #E02020; ">{</span>Chapitre 1<span style="color: #E02020; ">}</span>
        <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a>*<span style="color: #E02020; ">{</span>Une section<span style="color: #E02020; ">}</span>
        <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a><span style="color: #E02020; ">{</span>Une section avec un nom m?ga <span style="color: #E02020; ">\\</span>
            mais alors vraiment m?ga trop giga long qui d?passe<span style="color: #E02020; ">}</span>
        <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsection"><span style="color: #800000;">subsection</span></a><span style="color: #E02020; ">{</span>Une sous-section<span style="color: #E02020; ">}</span>
        <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsection"><span style="color: #800000;">subsection</span></a><span style="color: #E02020; ">{</span>Une sous-section<span style="color: #E02020; ">}</span>
    <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cchapter"><span style="color: #800000;">chapter</span></a><span style="color: #E02020; ">{</span>Chapitre 2<span style="color: #E02020; ">}</span>
        <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a><span style="color: #E02020; ">{</span>Une section<span style="color: #E02020; ">}</span>
            <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsection"><span style="color: #800000;">subsection</span></a><span style="color: #E02020; ">{</span>Une sous-section<span style="color: #E02020; ">}</span>
                <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cparagraph"><span style="color: #800000;">paragraph</span></a><span style="color: #E02020; ">{</span>Un paragraphe<span style="color: #E02020; ">}</span>
            <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csubsection"><span style="color: #800000;">subsection</span></a><span style="color: #E02020; ">{</span>Une sous-section<span style="color: #E02020; ">}</span>
                <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cparagraph"><span style="color: #800000;">paragraph</span></a><span style="color: #E02020; ">{</span>Un paragraphe<span style="color: #E02020; ">}</span>
        <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a><span style="color: #E02020; ">{</span>Une section<span style="color: #E02020; ">}</span>
    <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cchapter"><span style="color: #800000;">chapter</span></a><span style="color: #E02020; ">{</span>Chapitre 3<span style="color: #E02020; ">}</span>
        <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a><span style="color: #E02020; ">{</span>Une section<span style="color: #E02020; ">}</span>
        <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a><span style="color: #E02020; ">{</span>Une section<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:420px"><img src="https://www.sthda.com/french/french/upload/latex_table_matiere.png"/></div></center>
<!-- END HTML --><br />
<br />
<span class="warning"><br />
Notez qu'il manque les paragraphes, un titre est trop long.<br />
</span><br />
<br />
<h3 class="formatter-title">Param?trage d'une table des mati?res</h3><br />
<br />
 <h4 class="formatter-title">Renommer la table, en l'appelant "sommaire" </h4> <br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #2C922C; font-style: italic;">% Dans le corps du document,avant la commande \tableofcontents.</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Crenewcommand"><span style="color: #800000;">renewcommand</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\contentsname</span>}{Votre nouveau titre</span><span style="color: #E02020; ">}</span> 
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
La m?thode d?velopp?e ici est applicable aussi ? peu pr?s ? tous les ?l?ments de structure d'un document (pour changer l'appellation ? Partie ? en autre chose, il vous faudra remplacer \contentsname par \partname par exemple.).<br />
</span><br />
<br />
 <h4 class="formatter-title">Raccourcir une ligne</h4> <br />
Nous pouvons voir que dans notre sommaire, une des lignes est trop longue et d?passe. Heureusement, deux titres diff?rents peuvent ?tre fournis lors de la cr?ation d'un ?l?ment de structure : l'un pour le document, l'autre pour la table des mati?res.<br />
<br />
<span class="success"><br />
La commande <strong>\section{titre dans le document}</strong> se transforme en <strong>\section[titre court apparaissant dans la table des mati?res]{titre long apparaissant dans le document}</strong>.<br />
</span><br />
<br />
<br />
 <h4 class="formatter-title">Inclure les paragraphes dans le sommaire</h4> <br />
<br />
Chaque ?l?ment de hi?rarchie correspond ? un chiffre.<br />
<br />
<br />
<br />
<table class="formatter-table">
<tr class="formatter-table-row">
<th class="formatter-table-head">El?ment hi?rarchique</th>
                <th class="formatter-table-head">Nombre</th>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Partie</td>
<td class="formatter-table-col">-1</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Chapitre</td>
<td class="formatter-table-col">0</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Section</td>
<td class="formatter-table-col">1</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">sous-section</td>
<td class="formatter-table-col">2</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Sous-sous-section</td>
<td class="formatter-table-col">3</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Paragraphe</td>
<td class="formatter-table-col">4</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">Sous-paragraphe</td>
<td class="formatter-table-col">5</td>
</tr>
</table><br />
<br />
<br />
<span class="warning"><br />
La commande qui nous int?resse est <strong>\setcounter{tocdepth}{Nombre de votre choix}</strong>.  Elle sert ? demander ? LaTeX de composer une table des mati?res contenant tous les ?l?ments hi?rarchiques jusqu'? ceux d?finis par le nombre que vous aurez choisi<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #800000; font-weight: normal;">\setcounter</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">tocdepth}{4</span><span style="color: #E02020; ">}</span><span style="color: #2C922C; font-style: italic;">%Inclusion des paragraphes</span>
&nbsp;</pre></pre></div></span><br />
<br />
 <h4 class="formatter-title">Exclure un ?l?ment de structure</h4> <br />
<span class="notice"><br />
Lorsqu'un ?l?ment de structure est suivi de * (par exemple \chapter*{un chapitre}), il n'y a pas de r?f?rence vers celui-ci dans la table des mati?res.<br />
</span><br />
<br />
[page]Table des figures et des tableaux[/page]<br />
<br />
Elles s'ins?rent respectivement via les commandes <strong>\listoffigures </strong>et <strong>\listoftables</strong> ; elles font appara?tre, au choix, soit un titre sp?cialement con?u pour la table, soit la l?gende contenue dans \caption.<br />
<br />
<strong>Les deux syntaxes possibles ci-dessous vous sont pr?sent?es:</strong><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">titre court</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">l?gende normale de l'image<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a>{l?gende normale de l'image</span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">N'oubliez pas qu'il faut compiler deux fois pour faire apparaitre la table</span><br />
<br />
<br />
<strong><span style="color:blue;">Exemple :</span></strong><br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">12pt</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">report<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span><span style="color: #E02020; ">]{</span>inputenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span>fontenc<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">francais</span><span style="color: #E02020; ">]{</span>babel<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">{</span>graphicx<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">table</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>|c|c|<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">Un tableau</span><span style="color: #E02020; ">]{</span>Mon beau tableau<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">table</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">{</span>poulpy.png<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>Poulpy est multicolore<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">{</span>poulpy.png<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">Chatoyante</span><span style="color: #E02020; ">]{</span>Poulpy est chatoyante<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">{</span>poulpy.png<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>Poulpy est inestimable<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">table</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}{</span>|c|c|<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
1 <span style="color: #E02020; ">&</span> 2 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
3 <span style="color: #E02020; ">&</span> 4 <span style="color: #E02020; ">\\</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Chline"><span style="color: #800000;">hline</span></a>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">tabular</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>Mon beau tableau<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">table</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">{</span>poulpy.png<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">Poulpesque</span><span style="color: #E02020; ">]{</span>Poulpy est poulpesque<span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clistoftables"><span style="color: #800000;">listoftables</span></a>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clistoffigures"><span style="color: #800000;">listoffigures</span></a>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:650px; height:370px"><img src="https://www.sthda.com/french/french/upload/table_des_figures_tableau.png"/></div></center>
<!-- END HTML -->]]></description>
			<pubDate>Sun, 09 Jun 2013 19:51:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R et LaTeX: Sweave avec Rstudio]]></title>
			<link>https://www.sthda.com/french/articles/7-r/52-r-et-latex-sweave-avec-rstudio/</link>
			<guid>https://www.sthda.com/french/articles/7-r/52-r-et-latex-sweave-avec-rstudio/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
Sweave, un m?lange de R et du code LATEX,  permet de g?n?rer automatiquement un document contenant du code R, les r?sultats de ces codes et des commentaires. Ceci permet un gain de temps tr?s important permettant de g?n?rer des analyses reproductibles en cas d??ventuel changement des donn?es.<br />
<br />
<span class="warning"><br />
Un article sur LaTeX est disponible en suivant ce lien : <a href="https://www.sthda.com/french/french/articles/articles-19-53+latex.php">https://www.sthda.com/articles/articles-19-53+latex.php</a><br />
</span><br />
<br />
<h3 class="formatter-title">Logiciels r?quis</h3><br />
<br />
Il faudrait installer <a href="http://www.r-project.org/">R</a>, <a href="http://www.rstudio.com/">RStudio</a> et les outils Latex ( <a href="http://latex-project.org/ftp.html">http://latex-project.org/ftp.html</a>).<br />
<br />
<h3 class="formatter-title">Proc?dure</h3><br />
<br />
<strong>1- A partir de Rstudio, cr?er un fichier .Rnw en cliquant sur Fichier -> Nouveau -> R Sweave -> ?crire et enregistrez votre document </strong> : myfile.Rnw<br />
<strong>2- Compiler votre fichier en .pdf</strong><br />
<br />
<span class="notice">Lors de la compilation le fichier myfile.Rnw est tout d'abord converti en fichier LaTeX myfile.tex</span><br />
<br />
<h3 class="formatter-title">Squelette du fichier *.Rnw</h3><br />
<br />
Les codes R sont inclus entre les balises <<>>= et @ qui d?finissent ce que l'on appelle "chunk" :<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctitle"><span style="color: #800000;">title</span></a><span style="color: #E02020; ">{</span>Titre de mon document<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cauthor"><span style="color: #800000;">author</span></a><span style="color: #E02020; ">{</span>A Kass<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span>]{inputenc</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% Encodage pour ?criture de document en fran?ais</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%D?but du document</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cmaketitle"><span style="color: #800000;">maketitle</span></a> <span style="color: #2C922C; font-style: italic;">%Permet la cr?ation d'une page de garde (Autheur, Titre, Date)</span>
.
.
<<>>=
VOTRE CODE R ICI
@
.
.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Fin du document</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Les options basiques du chunk (morceaux de codes R) </h3><br />
<br />
<strong><span style="color:blue;">label :</span></strong> nom du chunk<br />
<strong><span style="color:blue;">echo :</span></strong> TRUE/FALSE. Affichage des commandes. Si TRUE, le code est affich?.  Valeur par d?faut : TRUE.<br />
<strong><span style="color:blue;">fig :</span></strong> TRUE/FALSE. Cr?ation d'un figure. Si TRUE, le graphique cr?? par le code est inclus. Valeur par d?faut : FALSE.<br />
<strong><span style="color:blue;">eval:</span></strong> TRUE/FALSE. Si FALSE, le morceau de code n'est pas ex?cut?. Valeur par d?faut : TRUE.<br />
<strong><span style="color:blue;">results:</span></strong> verbatim/hide/tex. Affichage des r?sultats des commandes. Si <strong>verbatim</strong>, le r?sultat est affich? comme dans l'environnement R. Si <strong>tex</strong>, le r?sultat du code est consid?r? comme du Latex et il est inclus comme tel. Si <strong>hide</strong>, le code est ex?cut? mais le r?sultat est non affich?. Valeur par defaut : verbatim. <br />
<strong><span style="color:blue;">prefix:</span></strong>TRUE/FALSE. If TRUE, les figures g?n?r?es et l'output ont le m?me prefix. Valeur par d?faut : TRUE.<br />
<strong><span style="color:blue;">prefix.string:</span></strong> prefix des fichiers g?n?r?s. La valeur par d?faut est le nom du fichier .Rnw.<br />
<strong><span style="color:blue;">include:</span></strong> TRUE/FALSE. Indique si le r?sultat text ou figure doit ?tre int?gr? automatiquement. <span style="color:red;">Utilisez include=FALSE, si le r?sultat doit appara?tre ? un endroit diff?rent du morceau de code (en pla?ant le r?sulat manuellement</span>).<br />
<strong><span style="color:blue;">eps:</span></strong> TRUE/FALSE. G?n?re des figures EPS.<br />
<strong><span style="color:blue;">width:</span></strong> Largeur des figures en inch (6).<br />
<strong><span style="color:blue;">height:</span></strong>Hauteur des figures en inch (6).<br />
<br />
<span class="notice"><br />
<br />
Les options peuvent ?tre configur?es globalement au d?but du fichier (et peuvent ?tre chang?es ailleurs au cas par cas) en utilisant la commande :<br />
<strong><span style="color:red;">\SweaveOpts(option1=value1,option2=value2,...)</span></strong><br />
<br />
Les options <strong><span style="color:red;">width</span></strong> et <strong><span style="color:red;">height</span></strong> correspondent ? la taille du graphique g?n?r? par R. Elles ne correspondent pas ? la taille du graphique inclus dans le document Latex.<br />
<br />
Pour changer la taille de la figure incluse dans le Latex, utiliser la commande :<br />
<strong><span style="color:red;">\setkeys{Gin}{width=0.8\textwidth}</span></strong> et changer 0.8 avec une autre valeur.<br />
On peut ?galement changer la taille manuellement en utilisant la commande d'inclusion manuelle: \includegraphics<br />
<br />
</span><br />
<br />
<br />
<br />
<h3 class="formatter-title">Exemple 1: Test statistique et graphique</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctitle"><span style="color: #800000;">title</span></a><span style="color: #E02020; ">{</span>Sweave Example 1<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cauthor"><span style="color: #800000;">author</span></a><span style="color: #E02020; ">{</span>Alboukadel Kassambara<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cmaketitle"><span style="color: #800000;">maketitle</span></a>
Dans cet exemple, nous allons inclure un exemple du test kuskal wallis et un boxplot analysant le param?tre ozone en fonction du mois:
&nbsp;
<<>>=
data(airquality)
kruskal.test(Ozone ~ Month, data = airquality)
@
La table contient <span style="color: #800000; font-weight: normal;">\Sexpr</span><span style="color: #E02020; ">{</span>nrow(airquality)<span style="color: #E02020; ">}</span> lignes et <span style="color: #800000; font-weight: normal;">\Sexpr</span><span style="color: #E02020; ">{</span>ncol(airquality)<span style="color: #E02020; ">}</span> colonnes.
Le test montre que la distribution du param?tre Ozone varie significativement de mois en mois. 
Enfin, nous incluons le boxplot des donn?es :
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<<label=figure1, fig=TRUE,echo=FALSE>>=
boxplot(Ozone ~ Month, data = airquality)
@
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">\Sexpr{} (comme dans l'exemple 1) permet d?ex?cuter du code R dans la documentation.</span><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/sweave_example_1_7e475.pdf" class="embed" >Resultat-Sweave-example-1</a>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Exemples 2 : Positionnement manuel d'une figure</h3><br />
<br />
Dans cet exemple la figure n'est pas positionn?e ? l'endroit du code ex?cut?. Elle est plac?e manuellement, un peu plus bas, dans le document LaTeX.<br />
<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctitle"><span style="color: #800000;">title</span></a><span style="color: #E02020; ">{</span>Sweave Exemple 2<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE, prefix.string=sthda<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cmaketitle"><span style="color: #800000;">maketitle</span></a>
<<label=histx,fig=TRUE,include=FALSE>>=
x<-rnorm(1000)
hist(x, col="lightblue", border="darkblue")
@
Dans cet exemple la figure n'est pas positionn?e ? l'endroit du code ex?cut?. Elle est plac?e manuellement, un peu plus bas, dans le document Latex.
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">h!</span><span style="color: #E02020; ">]</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">width=5in</span><span style="color: #E02020; ">]{</span>sthda-histx<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>Histogram of x.<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clabel"><span style="color: #800000;">label</span></a><span style="color: #E02020; ">{</span>histogram-x<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Lorsqu'on utilise <strong>\begin{figure}</strong>, la figure commence sur une nouvelle page. Pour ?viter cela, utilisez <strong><span style="color:blue;">\begin{figure}[h!]</span></strong><br />
</span><br />
<br />
<span class="success"><br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/sweave_example_2bis.pdf"><img src="https://www.sthda.com/french/french/sthda/images/pdf.png" class="valign_middle"/>Cliquez ici pour voir le PDF</a>
<!-- END HTML --><br />
</span><br />
<br />
<br />
<h3 class="formatter-title">Plusieurs graphiques dans un chunk</h3><br />
<br />
Il faudrait utiliser pdf() ou postscript () pour les cr?er et puis les ajouter dans le Latex.<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<<results=tex, echo=FALSE>>=
set.seed(672)
for(i in 1:4)<span style="color: #E02020; ">{</span>
file=paste("myfile", i, ".pdf", sep="")
pdf(file=file, paper="special", width=6, height=6)
plot(rnorm(100)+i)
dev.off()
cat("<span style="color: #E02020; ">\\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">height=2in, width=2in</span><span style="color: #E02020; ">]{</span>"
, file, "<span style="color: #E02020; ">}</span><span style="color: #800000; font-weight: normal;">\n</span>", sep="")
<span style="color: #E02020; ">}</span>
@
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<h3 class="formatter-title">Rappeler un morceau de code R par son nom</h3><br />
<span class="formatter-code">Code LATEXT :</span><div class="code"><pre style="display:inline;"><pre class="latext" style="font-family:monospace;">&nbsp;
<<a>>=
x <- 10
@
<<b>>=
x+y
@
<<c>>=
<<a>>
y <- 20
<<b>>
@</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Les figures </h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<<label=fig1,fig=TRUE,echo=FALSE>>=
hist(rnorm(1000,0,1)
@
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>Scatter Plot with Regression Line<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clabel"><span style="color: #800000;">label</span></a><span style="color: #E02020; ">{</span>fig:one<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Les tables</h3><br />
<br />
Installer le package xtable :<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"xtable"</span><span style="color: #080;">&#41;</span></pre></pre></div><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<<results=tex>>=
library(xtable)
x <- rnorm(100)
y <- 4 + 3 * x + rnorm(100, 0, 2)
lmodel <- lm(y ~ x)
lan <- anova(lmodel)
xtable(lmodel, caption = "La legende.",
label = "tab:coef" )
@
&nbsp;</pre></pre></div><br />
<br />
<span class="notice">Il est possible de faire reference a la table en utilisant le code :<br />
\ref{tab:coef} dans le code LATEX.</span><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:520px; height:290px"><img src="https://www.sthda.com/french/french/upload/sweave_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Exemple 3 : R?f?rencement des Tables et Figures dans la documentation</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<<echo=false,results=hide>>=
library(lattice)
library(xtable)
data(cats, package="MASS")
@
A linear regression model of heart weight by sex and gender can be
fitted in R using the command
<<>>=
lm1 = lm(Hwt~Bwt*Sex, data=cats)
lm1
@
Tests for significance of the coefficients are shown in
Table~<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cref"><span style="color: #800000;">ref</span></a><span style="color: #E02020; ">{</span>tab:coef<span style="color: #E02020; ">}</span>, a scatter plot including the regression lines is
shown in Figure~<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cref"><span style="color: #800000;">ref</span></a><span style="color: #E02020; ">{</span>fig:cats<span style="color: #E02020; ">}</span>.
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>echo=false<span style="color: #E02020; ">}</span>
<<results=tex>>=
xtable(lm1, caption="Linear regression model for cats data.",
label="tab:coef")
@
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccentering"><span style="color: #800000;">centering</span></a>
<<fig=TRUE,width=12,height=6>>=
trellis.par.set(col.whitebg())
print(xyplot(Hwt~Bwt|Sex, data=cats, type=c("p", "r")))
@
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>The cats data from package MASS.<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clabel"><span style="color: #800000;">label</span></a><span style="color: #E02020; ">{</span>fig:cats<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<span class="success"><br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/sweave_example_3.pdf"><img src="https://www.sthda.com/french/french/sthda/images/pdf.png" class="valign_middle"/>Cliquez ici pour voir le PDF</a>
<!-- END HTML --><br />
</span><br />
<br />
<br />
<h3 class="formatter-title">Extraction du code R ? partir d'un document Latex</h3><br />
<br />
La commande suivante permet d'extraire tous les codes R d'un fichier Latex :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">Stangle</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"myfile.Rnw"</span><span style="color: #080;">&#41;</span></pre></pre></div><br />
Un fichier .R est cr??.<br />
<br />
<br />
<h3 class="formatter-title">Une fonction R pour compiler du Sweave en pdf</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#usage :  ezSweave("sweave-example-4", preview=T)</span>
ezSweave<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span>filename, extension<span style="color: #080;">=</span><span style="color: #ff0000;">'Rnw'</span>, preview<span style="color: #080;">=</span>TRUE, encoding<span style="color: #080;">=</span><span style="color: #ff0000;">"ISO-8859-1"</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#123;</span>
  <span style="color: #0000FF; font-weight: bold;">Sweave</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span>filename,<span style="color: #ff0000;">"."</span>, extension,sep<span style="color: #080;">=</span><span style="color: #ff0000;">''</span><span style="color: #080;">&#41;</span>, encoding<span style="color: #080;">=</span>encoding<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>tools<span style="color: #080;">&#41;</span>
  texi2dvi<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span>filename,<span style="color: #ff0000;">".tex"</span>,sep<span style="color: #080;">=</span><span style="color: #ff0000;">''</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF; font-weight: bold;">pdf</span><span style="color: #080;">=</span>TRUE<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #080;">&#40;</span>preview<span style="color: #080;">&#41;</span>
  <span style="color: #080;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">options</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'pdfviewer'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#91;</span><span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#93;</span>,<span style="color: #ff0000;">' '</span>,filename,<span style="color: #ff0000;">'.pdf'</span>,sep<span style="color: #080;">=</span><span style="color: #ff0000;">''</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
  <span style="color: #080;">&#125;</span>
<span style="color: #080;">&#125;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Divers</h3><br />
<strong><span style="color:blue;"><br />
Sweaveinput{AnotherFile.Rnw} </span></strong>: Inclusion d'un autre fichier . Analogue ? la commande Latex \input ou \include<br />
<strong><span style="color:blue;">SweaveOpts{keep.source=TRUE}</span></strong> : Permet de garder les commentaires dans le code<br />
<strong><span style="color:blue;">SweaveOpts{}</span></strong> : Permet de changer les options par d?faut]]></description>
			<pubDate>Sat, 08 Jun 2013 10:09:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[RCMDR GGPLOT2]]></title>
			<link>https://www.sthda.com/french/articles/7-r/47-rcmdr-ggplot2/</link>
			<guid>https://www.sthda.com/french/articles/7-r/47-rcmdr-ggplot2/</guid>
			<description><![CDATA[<a href="http://www.r-bloggers.com/rggplot2r-bloggersrcmdrplugin-kmggplot2_0-0-3-is-on-cran-now/">http://www.r-bloggers.com/rggplot2r-bloggersrcmdrplugin-kmggplot2_0-0-3-is-on-cran-now/</a>]]></description>
			<pubDate>Sun, 09 Dec 2012 12:33:06 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Importing Data Into R from Different Sources]]></title>
			<link>https://www.sthda.com/french/articles/7-r/46-importing-data-into-r-from-different-sources/</link>
			<guid>https://www.sthda.com/french/articles/7-r/46-importing-data-into-r-from-different-sources/</guid>
			<description><![CDATA[<a href="http://www.r-bloggers.com/importing-data-into-r-from-different-sources/">http://www.r-bloggers.com/importing-data-into-r-from-different-sources/</a>]]></description>
			<pubDate>Fri, 07 Dec 2012 15:41:17 +0100</pubDate>
			
		</item>
		
	</channel>
</rss>
