|
52 | 52 | <varlistentry> |
53 | 53 | <term><parameter>offset</parameter></term> |
54 | 54 | <listitem> |
55 | | - <para> |
56 | | - The search offset. If it is not specified, 0 is used. |
| 55 | + <simpara> |
| 56 | + The search offset in characters. If it is not specified, 0 is used. |
57 | 57 | A negative offset counts from the end of the string. |
58 | | - </para> |
| 58 | + </simpara> |
59 | 59 | </listitem> |
60 | 60 | </varlistentry> |
61 | 61 | <varlistentry> |
|
70 | 70 |
|
71 | 71 | <refsect1 role="returnvalues"> |
72 | 72 | &reftitle.returnvalues; |
73 | | - <para> |
74 | | - Returns the numeric position of |
75 | | - the first occurrence of <parameter>needle</parameter> in the |
76 | | - <parameter>haystack</parameter> <type>string</type>. If |
77 | | - <parameter>needle</parameter> is not found, it returns &false;. |
78 | | - </para> |
| 73 | + <simpara> |
| 74 | + Returns the character position (not byte position) of the first occurrence |
| 75 | + of <parameter>needle</parameter> in the <parameter>haystack</parameter> |
| 76 | + <type>string</type>, counting from <literal>0</literal>. |
| 77 | + Returns &false; if <parameter>needle</parameter> is not found. |
| 78 | + </simpara> |
79 | 79 | </refsect1> |
80 | 80 |
|
81 | 81 | <refsect1 role="errors"> |
|
115 | 115 | </informaltable> |
116 | 116 | </refsect1> |
117 | 117 |
|
| 118 | + <refsect1 role="examples"> |
| 119 | + &reftitle.examples; |
| 120 | + <example> |
| 121 | + <title><function>mb_strpos</function> returns a character offset, not a byte offset</title> |
| 122 | + <programlisting role="php"> |
| 123 | +<![CDATA[ |
| 124 | +<?php |
| 125 | +// "🐘" is 4 bytes but 1 character; "é" is 2 bytes but 1 character |
| 126 | +$str = "🐘H🐘é"; |
| 127 | +
|
| 128 | +var_dump(mb_strpos($str, "é")); // character 3, not byte 9 |
| 129 | +var_dump(mb_strpos($str, "🐘", 1)); // character 2, skipping the first "🐘" |
| 130 | +?> |
| 131 | +]]> |
| 132 | + </programlisting> |
| 133 | + &example.outputs; |
| 134 | + <screen> |
| 135 | +<![CDATA[ |
| 136 | +int(3) |
| 137 | +int(2) |
| 138 | +]]> |
| 139 | + </screen> |
| 140 | + </example> |
| 141 | + </refsect1> |
| 142 | + |
118 | 143 | <refsect1 role="seealso"> |
119 | 144 | &reftitle.seealso; |
120 | 145 | <para> |
121 | 146 | <simplelist> |
| 147 | + <member><function>mb_strrpos</function></member> |
| 148 | + <member><function>mb_stripos</function></member> |
122 | 149 | <member><function>mb_internal_encoding</function></member> |
123 | 150 | <member><function>strpos</function></member> |
124 | 151 | </simplelist> |
|
0 commit comments