downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Commentaires> <Passer du HTML au PHP
Last updated: Fri, 14 Aug 2009

view this page in

Séparation des instructions

Comme en C ou en Perl, PHP requiert que les instructions soient terminées par un point-virgule à la fin de chaque instruction. La balise fermante d'un bloc de code PHP implique automatiquement un point-virgule ; vous n'avez pas besoin d'utiliser un point-virgule pour terminer la dernière ligne d'un bloc PHP. La balise fermante d'un bloc inclura immédiatement un caractère de nouvelle ligne si un est présent.

Exemple #1 Séparation des instructions

<?php
    
echo 'Ceci est un test';
?>

<?php echo 'Ceci est un test' ?>

<?php echo 'Oubli de la balise fermante';

Note: La balise fermante d'un bloc PHP à la fin d'un fichier est optionnel, et parfois, il est utile de l'omettre lors de l'utilisation de la fonction include() ou de la fonction require(), car les espaces non désirés n'apparaîtront pas à la fin des fichiers, et ainsi, vous pourrez toujours ajouter des en-têtes à la réponse plus tard. C'est utile également si vous voulez utiliser l'affichage du buffer et que vous ne voulez pas voir d'espaces blancs ajoutés à la fin des parties générées par les fichiers inclus.



Commentaires> <Passer du HTML au PHP
Last updated: Fri, 14 Aug 2009
 
add a note add a note User Contributed Notes
Séparation des instructions
Darabos, Edvrd Konrd
19-Aug-2008 10:58
One newline character (or sequence) is dropped out by the parser after "?>", so you can add the beloved "final newline" to your file after "?>"

Example for plain text outputs:

<? foreach($array as $elem){ ?>
Value: <?=$elem?>

<? } ?>

(You have to add an extra enter after <?=$elem?> if you want to see a newline in the output.
james dot d dot noyes at lmco dot com
05-May-2008 06:42
If you are embedding this in XML, you had better place the ending '?>' there or the XML parser will puke on you.  XML parsers do not like processing instructions without end tags, regardless of what PHP does.

If you're doing HTML like 90% of the world, or if you are going to process/interpret the PHP before the XML parser ever sees it, then you can likely get away with it, but it's still not best practice for XML.
Sam H
18-Apr-2008 07:17
Best not to exclude ?> ever, just for code cleanliness' sake.
Krishna Srikanth
17-Aug-2006 11:44
Do not mis interpret

<?php echo 'Ending tag excluded';

with

<?php echo 'Ending tag excluded';
<
p>But html is still visible</p>

The second one would give error. Exclude ?> if you no more html to write after the code.

Commentaires> <Passer du HTML au PHP
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites