cvs: phpdoc /en/reference/strings/functions strpos.xml

From: Date: Thu, 20 Feb 2003 16:40:20 +0000
Subject: cvs: phpdoc /en/reference/strings/functions strpos.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969351879@lists.php.net to get a copy of this message
philip Thu Feb 20 11:40:20 2003 EDT Modified files: /phpdoc/en/reference/strings/functions strpos.xml Log: Expand example, remove old example, use &return.falseproblem; and see also stripos() Index: phpdoc/en/reference/strings/functions/strpos.xml diff -u phpdoc/en/reference/strings/functions/strpos.xml:1.2 phpdoc/en/reference/strings/functions/strpos.xml:1.3 --- phpdoc/en/reference/strings/functions/strpos.xml:1.2 Wed Apr 17 02:44:23 2002 +++ phpdoc/en/reference/strings/functions/strpos.xml Thu Feb 20 11:40:20 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- splitted from ./en/functions/strings.xml, last change in rev 1.8 --> <refentry id="function.strpos"> <refnamediv> @@ -25,31 +25,35 @@ entire string will be used. </para> <para> - If <parameter>needle</parameter> is not found, returns &false;. - <note> - <para> - It is easy to mistake the return values for "character found at - position 0" and "character not found". Here's how to detect - the difference: - <informalexample> - <programlisting role="php"> + If <parameter>needle</parameter> is not found, + <function>strpos</function> will return <type>boolean</type> &false;. + </para> + + &return.falseproblem; + + <para> + <example> + <title><function>strpos</function> examples</title> + <programlisting role="php"> <![CDATA[ -// in PHP 4.0b3 and newer: -$pos = strpos($mystring, "b"); -if ($pos === false) { // note: three equal signs - // not found... -} +<?php +$mystring = 'abc'; +$findme = 'a'; +$pos = strpos($mystring, $findme); -// in versions older than 4.0b3: -$pos = strpos($mystring, "b"); -if (!is_integer($pos)) { - // not found... +// Note our use of ===. Simply == would not work as expected +// because the position of 'a' was the 0th (first) character. +if ($pos === false) { + echo "The string '$findme' was not found in the string '$mystring'"; +} else { + echo "The string '$findme' was found in the string '$mystring'"; + echo " and exists at position $pos"; } + +?> ]]> - </programlisting> - </informalexample> - </para> - </note> + </programlisting> + </example> </para> <para> If <parameter>needle</parameter> is not a string, it is converted @@ -62,7 +66,7 @@ the beginning of <parameter>haystack</parameter>. </para> <para> - See also <function>strrpos</function>, + See also <function>strrpos</function>, <function>stripos</function>, <function>strrchr</function>, <function>substr</function>, <function>stristr</function>, and <function>strstr</function>. </para>

« previous php.doc (#969351879) next »