mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-04-24 00:58:12 +02:00
a3a924dae9
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@171652 c90b9560-bf6c-de11-be94-00142212c4b1
102 lines
3.3 KiB
XML
102 lines
3.3 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.12 $ -->
|
|
<!-- EN-Revision: 1.6 Maintainer: didou Status: ready -->
|
|
<refentry id="function.strpos">
|
|
<refnamediv>
|
|
<refname>strpos</refname>
|
|
<refpurpose>
|
|
Trouve la position d'un caractère dans une chaîne
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>strpos</methodname>
|
|
<methodparam><type>string</type><parameter>haystack</parameter></methodparam>
|
|
<methodparam><type>mixed</type><parameter>needle</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>offset</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>strpos</function> retourne la position numérique de la première
|
|
occurrence de <parameter>needle</parameter> dans la chaîne de caractères
|
|
<parameter>haystack</parameter>. Contrairement à la fonction
|
|
<function>strrpos</function>, celle-ci peut prendre une chaîne de caractères
|
|
complète comme paramètre <parameter>needle</parameter> et cette chaîne sera
|
|
utilisée en totalité.
|
|
</para>
|
|
<para>
|
|
Si <parameter>needle</parameter> n'est pas trouvée, la fonction retourne &false;.
|
|
</para>
|
|
&return.falseproblem;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>strpos</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$mystring = 'abc';
|
|
$findme = 'a';
|
|
$pos = strpos($mystring, $findme);
|
|
|
|
// Notez l'utilisation de ===. Un simple == ne donnerait pas le résultat escompté
|
|
// car la lettre 'a' est à la position 0 (la première).
|
|
if ($pos === false) {
|
|
echo "La chaîne '$findme' n'a pas été trouvée dans la chaîne '$mystring'";
|
|
} else {
|
|
echo "La chaîne '$findme' a été trouvée dans la chaîne '$mystring'";
|
|
echo " et à la position $pos";
|
|
}
|
|
|
|
// On peut chercher le caractère, en ignorant tout avant une position
|
|
$newstring = 'abcdef abcdef';
|
|
$pos = strpos($newstring, 'a', 1); // $pos = 7, pas 0
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Si <parameter>needle</parameter> n'est pas une chaîne, elle est
|
|
convertie en entier, et utilisé comme caractère de code ASCII
|
|
correspondant.
|
|
</para>
|
|
<para>
|
|
Le paramètre optionnel <parameter>offset</parameter> vous permet
|
|
de spécifier à partir de quel caractère dans <parameter>haystack</parameter>
|
|
vous souhaitez commencer la recherche. La position retournée sera toujours
|
|
relative au début de la chaîne <parameter>haystack</parameter>.
|
|
</para>
|
|
<para>
|
|
Voir aussi
|
|
<function>strrpos</function>,
|
|
<function>stripos</function>,
|
|
<function>strripos</function>,
|
|
<function>strrchr</function>,
|
|
<function>substr</function>,
|
|
<function>stristr</function> et
|
|
<function>strstr</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
|
|
-->
|