mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 16:32:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@331213 c90b9560-bf6c-de11-be94-00142212c4b1
178 lines
5.0 KiB
XML
178 lines
5.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 5b39c74139ed16e20f683c6cc5e80c57b9a565ba Maintainer: jpberdejo Status: ready -->
|
|
<!-- Reviewed: no Maintainer: andresdzphp -->
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.strpos">
|
|
<refnamediv>
|
|
<refname>strpos</refname>
|
|
<refpurpose>Encuentra la posición de la primera ocurrencia de un substring en un string</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mixed</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><initializer>0</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Encuentra la posición numérica de la primera ocurrencia del
|
|
<parameter>needle</parameter> (aguja) en el string <parameter>haystack</parameter> (pajar).
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>haystack</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El string en donde buscar.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>needle</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si la <parameter>needle</parameter> no es una cadena, es convertida a
|
|
integer y se interpreta como el valor ordinal de un carácter.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>offset</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si se específica, la búsqueda iniciará en éste número de caracteres contados desde
|
|
el inicio del string. A diferencia de <function>strrpos</function> y
|
|
<function>strripos</function>, el offset no puede ser negativo.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Devuelve la posición donde la aguja existe, en relación al inicio del
|
|
string <parameter>haystack</parameter> (independiente del offset).
|
|
También tener en cuenta que las posiciones de inicio de los string empiezan en 0 y no 1.
|
|
</para>
|
|
<para>
|
|
Devuelve &false; si no fue encontrada la aguja.
|
|
</para>
|
|
&return.falseproblem;
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Usando <literal>===</literal></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$mystring = 'abc';
|
|
$findme = 'a';
|
|
$pos = strpos($mystring, $findme);
|
|
|
|
// Nótese el uso de ===. Puesto que == simple no funcionará como se espera
|
|
// porque la posición de 'a' está en el 1° (primer) caracter.
|
|
if ($pos === false) {
|
|
echo "La cadena '$findme' no fue encontrada en la cadena '$mystring'";
|
|
} else {
|
|
echo "La cadena '$findme' fue encontrada en la cadena '$mystring'";
|
|
echo " y existe en la posición $pos";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Using !==</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$mystring = 'abc';
|
|
$findme = 'a';
|
|
$pos = strpos($mystring, $findme);
|
|
|
|
// El operador !== también puede ser usado. Puesto que != no funcionará como se espera
|
|
// porque la posición de 'a' es 0. La declaración (0 != false) se evalúa a
|
|
// false.
|
|
if ($pos !== false) {
|
|
echo "La cadena '$findme' fue encontrada en la cadena '$mystring'";
|
|
echo " y existe en la posición $pos";
|
|
} else {
|
|
echo "La cadena '$findme' no fue encontrada en la cadena '$mystring'";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Uso de offset</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Se puede buscar por el caracter, ignorando cualquier cosa antes del offset
|
|
$newstring = 'abcdef abcdef';
|
|
$pos = strpos($newstring, 'a', 1); // $pos = 7, no 0
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
¬e.bin-safe;
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>stripos</function></member>
|
|
<member><function>strrpos</function></member>
|
|
<member><function>strripos</function></member>
|
|
<member><function>strstr</function></member>
|
|
<member><function>strpbrk</function></member>
|
|
<member><function>substr</function></member>
|
|
<member><function>preg_match</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
|
|
-->
|