mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-25 09:22:07 +01:00
222 lines
5.9 KiB
XML
222 lines
5.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 7a3899eea90f3df8dcfe8fd350900162f3490bed Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<refentry xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://docbook.org/ns/docbook" xml:id="function.print">
|
|
<refnamediv>
|
|
<refname>print</refname>
|
|
<refpurpose>Affiche une chaîne de caractères</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>print</methodname>
|
|
<methodparam><type>string</type><parameter>expression</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Affiche <parameter>expression</parameter>.
|
|
</para>
|
|
<para>
|
|
<literal>print</literal> n'est pas une fonction mais une construction du langage.
|
|
Son argument est l'expression suivant le mot clé <literal>print</literal>,
|
|
et n'est pas délimité par des parenthèses.
|
|
</para>
|
|
<para>
|
|
La différence majeure avec <literal>echo</literal> est que
|
|
<literal>print</literal> n'accepte qu'un seul argument et retourne toujours 1.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>expression</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
L'expression à afficher. Les valeurs qui ne sont pas des chaînes de
|
|
caractères seront converties en celle-ci, même si la
|
|
<link linkend="language.types.declarations.strict">directive
|
|
<literal>strict_types</literal></link> est activé.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retourne <literal>1</literal>, toujours.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <literal>print</literal></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
print "print does not require parentheses.";
|
|
|
|
// No newline or space is added; the below outputs "helloworld" all on one line
|
|
print "hello";
|
|
print "world";
|
|
|
|
print "This string spans
|
|
multiple lines. The newlines will be
|
|
output as well";
|
|
|
|
print "This string spans\nmultiple lines. The newlines will be\noutput as well.";
|
|
|
|
// The argument can be any expression which produces a string
|
|
$foo = "example";
|
|
print "foo is $foo"; // foo is example
|
|
|
|
$fruits = ["lemon", "orange", "banana"];
|
|
print implode(" and ", $fruits); // lemon and orange and banana
|
|
|
|
// Non-string expressions are coerced to string, even if declare(strict_types=1) is used
|
|
print 6 * 7; // 42
|
|
|
|
// Because print has a return value, it can be used in expressions
|
|
// The following outputs "hello world"
|
|
if ( print "hello" ) {
|
|
echo " world";
|
|
}
|
|
|
|
// The following outputs "true"
|
|
( 1 === 1 ) ? print 'true' : print 'false';
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
|
|
<note>
|
|
<title>Utilisation avec des parenthèses</title>
|
|
<para>
|
|
Entourer l'argument de <literal>print</literal> 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'expression qui est en cours
|
|
d'affichage, et non partie de la syntaxe de <literal>print</literal>
|
|
en lui-même.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title/>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
print "hello";
|
|
// outputs "hello"
|
|
|
|
print("hello");
|
|
// also outputs "hello", because ("hello") is a valid expression
|
|
|
|
print(1 + 2) * 3;
|
|
// outputs "9"; the parentheses cause 1+2 to be evaluated first, then 3*3
|
|
// the print statement sees the whole expression as one argument
|
|
|
|
if ( print("hello") && false ) {
|
|
print " - inside if";
|
|
}
|
|
else {
|
|
print " - inside else";
|
|
}
|
|
// outputs " - inside if"
|
|
// the expression ("hello") && false is first evaluated, giving false
|
|
// this is coerced to the empty string "" and printed
|
|
// the print construct then returns 1, so code in the if block is run
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
|
|
<para>
|
|
Quand <literal>print</literal> est utilisé dans une expression plus large,
|
|
placer tout deux le mot clé et son argument dans les parenthèses peut être
|
|
nécessaire pour obtenir le résultat attendu :
|
|
</para>
|
|
|
|
<para>
|
|
<example>
|
|
<title/>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
if ( (print "hello") && false ) {
|
|
print " - inside if";
|
|
}
|
|
else {
|
|
print " - inside else";
|
|
}
|
|
// outputs "hello - inside else"
|
|
// unlike the previous example, the expression (print "hello") is evaluated first
|
|
// after outputting "hello", print returns 1
|
|
// since 1 && false is false, code in the else block is run
|
|
|
|
print "hello " && print "world";
|
|
// outputs "world1"; print "world" is evaluated first,
|
|
// then the expression "hello " && 1 is passed to the left-hand print
|
|
|
|
(print "hello ") && (print "world");
|
|
// outputs "hello world"; the parentheses force the print expressions
|
|
// to be evaluated before the &&
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</note>
|
|
|
|
¬e.language-construct;
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>echo</function></member>
|
|
<member><function>printf</function></member>
|
|
<member><function>flush</function></member>
|
|
<member><link linkend="language.types.string">Manière de spécifié des chaînes littérales</link></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|