Current Location: Home> Function Categories> stristr

stristr

Case-insensitive strstr
Name:stristr
Category:String
Programming Language:php
One-line Description:Find where the string first appears in another string (case insensitive).

Example

Example 1

Find the first occurrence of "world" in "Hello world!" and return the remainder of the string:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strstr</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello world!"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"WORLD"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Try it yourself

Example 2

Search the string with the ASCII value of "o" and return the remainder of the string:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strstr</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello world!"</span> <span class="token punctuation">,</span> <span class="token number">111</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Try it yourself

Example 2

Returns the string part before the first occurrence of "world":

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strstr</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello world!"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"WORLD"</span> <span class="token punctuation">,</span> <span class="token constant boolean">true</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Try it yourself