mirror of
https://github.com/php/doc-fr.git
synced 2026-03-25 23:52:20 +01:00
182 lines
5.1 KiB
XML
182 lines
5.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 45042fef652f1b4e904e809fcbfcf31f6c60670b Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
<refentry xml:id="function.substr-count" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>substr_count</refname>
|
|
<refpurpose>Compte le nombre d'occurrences de segments dans une chaîne</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>substr_count</methodname>
|
|
<methodparam><type>string</type><parameter>haystack</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>needle</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>offset</parameter><initializer>0</initializer></methodparam>
|
|
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>length</parameter><initializer>&null;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>substr_count</function> retourne le nombre d'occurrences
|
|
de <parameter>needle</parameter> dans la chaîne
|
|
<parameter>haystack</parameter>. Il est à noter que <parameter>needle</parameter>
|
|
est sensible à la casse.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Cette fonction ne compte pas les chaînes de caractères qui se recouvrent.
|
|
Voir l'exemple ci-dessous !
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>haystack</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La chaîne de caractères pour rechercher à l'intérieur
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>needle</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La chaîne de caractères que l'on recherche
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>offset</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Le décalage où on commence à compter. Si la position est négative,
|
|
le comptage commence depuis la fin de la chaîne.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>length</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La taille maximale après le décalage spécifié pour rechercher la
|
|
chaîne. La fonction émet une erreur si le décalage plus la taille est
|
|
plus grand que la taille de <parameter>haystack</parameter>.
|
|
Une taille négative fera que le comptage commencera à la fin de
|
|
<parameter>haystack</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Cette fonction retourne un &integer;.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
<parameter>length</parameter> est désormais nullable.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>7.1.0</entry>
|
|
<entry>
|
|
Ajout du support des nombres négatifs pour <parameter>offset</parameter>
|
|
et <parameter>length</parameter>.
|
|
<parameter>length</parameter> peut aussi être <literal>0</literal> maintenant.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>substr_count</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$text = 'Ceci est un test';
|
|
echo strlen($text), PHP_EOL; // 16
|
|
|
|
echo substr_count($text, 'est'), PHP_EOL; // 2
|
|
|
|
// la chaîne de caractères est réduite à 'st un test', alors elle affiche 1
|
|
echo substr_count($text, 'est', 6), PHP_EOL;
|
|
|
|
// le texte est réduit à 'st u', alors elle affiche 0
|
|
echo substr_count($text, 'is', 3, 3), PHP_EOL;
|
|
|
|
// affiche seulement 1, parce qu'elle ne compte pas les chaînes de caractères
|
|
// qui se recouvrent
|
|
$text2 = 'gcdgcdgcd';
|
|
echo substr_count($text2, 'gcdgcd'), PHP_EOL;
|
|
|
|
// lève une exception parce que 5+10 > 14
|
|
echo substr_count($text, 'is', 5, 10), PHP_EOL;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>count_chars</function></member>
|
|
<member><function>strpos</function></member>
|
|
<member><function>substr</function></member>
|
|
<member><function>strstr</function></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
|
|
-->
|