<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.print.php',
    1 => 'print',
    2 => 'Affiche une cha&icirc;ne de caract&egrave;res',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'Fonctions sur les cha&icirc;nes de caract&egrave;res',
  ),
  'prev' => 
  array (
    0 => 'function.parse-str.php',
    1 => 'parse_str',
  ),
  'next' => 
  array (
    0 => 'function.printf.php',
    1 => 'printf',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/strings/functions/print.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.print" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">print</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">print</span> &mdash; <span class="dc-title">Affiche une chaîne de caractères</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.print-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>print</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$expression</code></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   Affiche <code class="parameter">expression</code>.
  </p>
  <p class="para">
   <code class="literal">print</code> n&#039;est pas une fonction mais une construction du langage.
   Son argument est l&#039;expression suivant le mot clé <code class="literal">print</code>,
   et n&#039;est pas délimité par des parenthèses.
  </p>
  <p class="para">
   La différence majeure avec <span class="function"><a href="function.echo.php" class="function">echo</a></span> est que
   <code class="literal">print</code> n&#039;accepte qu&#039;un seul argument et retourne toujours 1.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.print-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">expression</code></dt>
     <dd>
      <p class="para">
       L&#039;expression à afficher. Les valeurs qui ne sont pas des chaînes de
       caractères seront converties en celle-ci, même si la
       <a href="language.types.declarations.php#language.types.declarations.strict" class="link">directive
       <code class="literal">strict_types</code></a> est activée.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.print-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne <code class="literal">1</code>, toujours.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.print-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <code class="literal">print</code></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"print does not require parentheses."</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Aucune nouvelle ligne ou espace n'est ajoutée ; ci-dessous affiche "helloworld", tout sur une ligne<br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"world"</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"This string spans<br />multiple lines. The newlines will be<br />output as well"</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"This string spans\nmultiple lines. The newlines will be\noutput as well."</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// L'argument peut être n'importe quelle expression qui produit une chaîne de caractères<br /></span><span style="color: #0000BB">$foo </span><span style="color: #007700">= </span><span style="color: #DD0000">"example"</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"foo is </span><span style="color: #0000BB">$foo</span><span style="color: #DD0000">"</span><span style="color: #007700">; </span><span style="color: #FF8000">// foo is example<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$fruits </span><span style="color: #007700">= [</span><span style="color: #DD0000">"lemon"</span><span style="color: #007700">, </span><span style="color: #DD0000">"orange"</span><span style="color: #007700">, </span><span style="color: #DD0000">"banana"</span><span style="color: #007700">];<br />print </span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">" and "</span><span style="color: #007700">, </span><span style="color: #0000BB">$fruits</span><span style="color: #007700">); </span><span style="color: #FF8000">// lemon and orange and banana<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Les expressions qui ne sont pas des chaînes sont converties en chaînes, même si declare(strict_types=1) est utilisé<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">6 </span><span style="color: #007700">* </span><span style="color: #0000BB">7</span><span style="color: #007700">; </span><span style="color: #FF8000">// 42<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Parce que print a une valeur de retour, il peut être utilisé dans des expressions<br />// Le code suivant affiche "hello world"<br /></span><span style="color: #007700">if ( print </span><span style="color: #DD0000">"hello" </span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">" world"</span><span style="color: #007700">;<br />}<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Le code suivant affiche "true"<br /></span><span style="color: #007700">( </span><span style="color: #0000BB">1 </span><span style="color: #007700">=== </span><span style="color: #0000BB">1 </span><span style="color: #007700">) ? print </span><span style="color: #DD0000">'true' </span><span style="color: #007700">: print </span><span style="color: #DD0000">'false'</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.print-notes">
  <h3 class="title">Notes</h3>

  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>Utilisation avec des parenthèses</strong><br />
   <p class="para">
    Entourer l&#039;argument de <code class="literal">print</code> avec des parenthèses
    ne lèvera pas une erreur de syntaxe, et produit une syntaxe ressemblant à un
    appel normal de fonction. Néanmoins, ceci peut être trompeur, car les
    parenthèses font en réalité partie de l&#039;expression qui est en cours
    d&#039;affichage, et non partie de la syntaxe de <code class="literal">print</code>
    en lui-même.
    <div class="informalexample">
     <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// affiche "hello"<br /><br /></span><span style="color: #007700">print(</span><span style="color: #DD0000">"hello"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// affiche également "hello", car ("hello") est une expression valide<br /><br /></span><span style="color: #007700">print(</span><span style="color: #0000BB">1 </span><span style="color: #007700">+ </span><span style="color: #0000BB">2</span><span style="color: #007700">) * </span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// affiche "9" ; les parenthèses permettent à 1+2 d'être évalué en premier, puis 3*3<br />// l'instruction print voit l'expression entière comme un seul argument<br /><br /></span><span style="color: #007700">if ( print(</span><span style="color: #DD0000">"hello"</span><span style="color: #007700">) &amp;&amp; </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br />    print </span><span style="color: #DD0000">" - inside if"</span><span style="color: #007700">;<br />}<br />else {<br />    print </span><span style="color: #DD0000">" - inside else"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #FF8000">// affiche " - inside if"<br />// l'expression ("hello") &amp;&amp; false est d'abord évaluée, donnant false<br />// celle-ci est convertie en chaîne vide "" et affichée<br />// la construction print retourne alors 1, donc le code du bloc if est exécuté<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

    </div>
   </p>

   <p class="para">
    Quand <code class="literal">print</code> est utilisé dans une expression plus large,
    placer tous deux le mot clé et son argument dans les parenthèses peut être
    nécessaire pour obtenir le résultat attendu :
   <div class="informalexample">
     <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if ( (print </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">) &amp;&amp; </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br />    print </span><span style="color: #DD0000">" - inside if"</span><span style="color: #007700">;<br />}<br />else {<br />    print </span><span style="color: #DD0000">" - inside else"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #FF8000">// affiche "hello - inside else"<br />// contrairement à l'exemple précédent, l'expression (print "hello") est évaluée en premier<br />// après avoir affiché "hello", print retourne 1<br />// puisque 1 &amp;&amp; false vaut false, le code du bloc else est exécuté<br /><br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"hello " </span><span style="color: #007700">&amp;&amp; print </span><span style="color: #DD0000">"world"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// affiche "world1" ; print "world" est évalué en premier,<br />// puis l'expression "hello " &amp;&amp; 1 est passée au print de gauche<br /><br /></span><span style="color: #007700">(print </span><span style="color: #DD0000">"hello "</span><span style="color: #007700">) &amp;&amp; (print </span><span style="color: #DD0000">"world"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// affiche "hello world" ; les parenthèses forcent les expressions print<br />// à être évaluées avant le &amp;&amp;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

    </div>
   </p>
  </p></blockquote>

  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Comme ceci est une structure
    du langage, et non pas une fonction, il n&#039;est pas possible de l&#039;appeler
    avec les <a href="functions.variable-functions.php" class="link">fonctions variables</a> ou <a href="functions.arguments.php#functions.named-arguments" class="link">arguments nommés</a>.
</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.print-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.echo.php" class="function" rel="rdfs-seeAlso">echo</a> - Affiche une cha&icirc;ne de caract&egrave;res</span></li>
    <li><span class="function"><a href="function.printf.php" class="function" rel="rdfs-seeAlso">printf()</a> - Affiche une cha&icirc;ne de caract&egrave;res format&eacute;e</span></li>
    <li><span class="function"><a href="function.flush.php" class="function" rel="rdfs-seeAlso">flush()</a> - Vide les tampons de sortie du syst&egrave;me</span></li>
    <li><a href="language.types.string.php" class="link">Manière de spécifier des chaînes littérales</a></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>