Expand example, remove old example, use &return.falseproblem; and see also stripos()

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@117355 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2003-02-20 16:40:20 +00:00
parent 022c09565b
commit ad44aca38e

View file

@ -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);
// 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";
}
// in versions older than 4.0b3:
$pos = strpos($mystring, "b");
if (!is_integer($pos)) {
// not found...
}
?>
]]>
</programlisting>
</informalexample>
</para>
</note>
</programlisting>
</example>
</para>
<para>
If <parameter>needle</parameter> is not a string, it is converted
@ -62,7 +66,7 @@ if (!is_integer($pos)) {
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>