Files
doc-fr/reference/strings/functions/substr.xml
Yannick Torres 94dd40b5cb sync with EN revision
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@162594 c90b9560-bf6c-de11-be94-00142212c4b1
2004-07-03 14:53:50 +00:00

123 lines
4.0 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- EN-Revision: 1.9 Maintainer: didou Status: ready -->
<refentry id="function.substr">
<refnamediv>
<refname>substr</refname>
<refpurpose>Retourne un segment de chaîne</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>substr</methodname>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam><type>int</type><parameter>start</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>
<function>substr</function> retourne le segment de
<parameter>string</parameter> défini par <parameter>start</parameter> et
<parameter>length</parameter>.
</para>
<para>
Si <parameter>start</parameter> est positif, la chaîne
retournée commencera au caractère numéro <parameter>start</parameter>,
dans la chaîne <parameter>string</parameter>. Le premier caractère
est numéroté zéro.
</para>
<example>
<title>Exemple avec <function>substr</function></title>
<programlisting role="php">
<![CDATA[
<?php
$rest = substr("abcdef", 1); // retourne "bcdef"
$rest = substr("abcdef", 1, 3); // retourne "bcd"
$rest = substr("abcdef", 0, 4); // retourne "abcd"
$rest = substr("abcdef", 0, 8); // retourne "abcdef"
// Accéder aux caractères via les accolades
$string = 'abcdef';
echo $string{0}; // retourne a
echo $string{3}; // retourne d
?>
]]>
</programlisting>
</example>
<para>
Si <parameter>start</parameter> est négatif, la chaîne retournée
commencera au <parameter>start</parameter>'ième caractère depuis
la fin de la chaîne <parameter>string</parameter>.
</para>
<example>
<title>Exemple de <parameter>start</parameter> négatif</title>
<programlisting role="php">
<![CDATA[
<?php
$rest = substr("abcdef", -1); // retourne "f"
$rest = substr("abcdef", -2); // retourne "ef"
$rest = substr("abcdef", -3, 1); // retourne "d"
?>
]]>
</programlisting>
</example>
<para>
Si <parameter>length</parameter> est fourni et est positif,
la chaîne retournée contiendra au plus <parameter>length</parameter>
caractères, en commençant à partir du caractère <parameter>start</parameter>
(en fonction de la taille de la chaîne <parameter>string</parameter>).
Si <parameter>string</parameter> est plus petite que
<parameter>start</parameter>, <function>substr</function> retournera
&false;.
</para>
<para>
Si <parameter>length</parameter> est fourni et négatif, alors le même
nombre de caractères sera omis, en partant de la fin de la chaîne
<parameter>string</parameter>. Si <parameter>start</parameter> représente
une position hors de la chaîne, une chaîne vide sera retournée.
</para>
<example>
<title>Utiliser une valeur négative de <parameter>length</parameter></title>
<programlisting role="php">
<![CDATA[
<?php
$rest = substr("abcdef", 0, -1); // retourne "abcde"
$rest = substr("abcdef", 2, -1); // retourne "cde"
$rest = substr("abcdef", 4, -4); // retourne ""
$rest = substr("abcdef", -3, -1); // retourne "de"
?>
]]>
</programlisting>
</example>
<para>
Voir aussi
<function>strrchr</function>,
<function>substr_replace</function>,
<function>ereg</function>,
<function>trim</function>,
<function>mb_substr</function> et
<function>wordwrap</function>.
</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:"../../../../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
-->