Current Location: Home> Function Categories> strrchr

strrchr

Find the last occurrence of a specified character in a string
Name:strrchr
Category:String
Programming Language:php
One-line Description:Find the last time a string appears in another string.

Example

Example 1

Search for the position of "Shanghai" in the string and return all characters from that position to the end 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">strchr</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"I love Shanghai!"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"Shanghai"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Try it yourself

Example 2

Search for the position of "What" in the string and return all characters from that position to the end 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">strchr</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello world! What a beautiful day!"</span> <span class="token punctuation">,</span> What <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Try it yourself

Example 3

Searches for the position of "o" in the string with the ASCII value of "o" and returns all characters from that position to the end 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">strchr</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">101</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Try it yourself

Similar Functions