<span><span><span class="hljs-meta"><?php</span></span><span>
</span><span><span class="hljs-comment">// This code section is unrelated to the article content and is just a sample introduction</span></span><span>
</span><span><span class="hljs-keyword">echo</span></span><span> </span><span><span class="hljs-string">"This is a sample introduction code.\n"</span></span><span>;
</span><span><span class="hljs-meta">?></span></span><span>
<p><hr></p>
<p></span><?php<br>
/**</p>
<ul>
<li>
<p>Detailed Usage of strrchr Function: How to Return the Content After the Last Character in a String</p>
</li>
<li></li>
<li>
<p>In PHP, the strrchr() function is used to find the last occurrence of a character in a string</p>
</li>
<li>
<p>and returns that character along with everything after it. This article provides a detailed guide on how to use this function with examples.</p>
</li>
<li></li>
<li>
<p>Function Prototype:</p>
</li>
<li>
<p>string strrchr ( string $haystack , mixed $needle )</p>
</li>
<li></li>
<li>
<p>Parameters:</p>
</li>
<li>
<ul>
<li>
<p>$haystack: The string to search in.</p>
</li>
</ul>
</li>
<li>
<ul>
<li>
<p>$needle: The character to find. Only the first character will be used for searching.</p>
</li>
</ul>
</li>
<li></li>
<li>
<p>Return Value:</p>
</li>
<li>
<ul>
<li>
<p>Returns the substring from the last occurrence of $needle to the end of the string.</p>
</li>
</ul>
</li>
<li>
<ul>
<li>
<p>Returns FALSE if the character is not found.</p>
</li>
</ul>
</li>
<li></li>
<li>
<ol>
<li>
<p>Basic Usage Example<br>
*/<br>
$str = "hello world";<br>
$lastPart = strrchr($str, 'o');<br>
echo "String: $str\n";<br>
echo "Content after character 'o':" . $lastPart . \n";<br>
// Output: o world</p>
</li>
</ol>
</li>
</ul>
<p>/**</p>
<ul>
<li>
<p>2. Notes</p>
</li>
<li>
<ul>
<li>
<p>The $needle parameter only takes the first character; extra characters are ignored.</p>
</li>
</ul>
</li>
<li>
<ul>
<li>
<p>If $needle is a string, only its first character is used for searching.</p>
</li>
</ul>
</li>
<li>
<ul>
<li>
<p>If the specified character is not found, the function returns FALSE.<br>
*/</p>
</li>
</ul>
</li>
</ul>
<p>// Find character 'l'<br>
$result = strrchr($str, 'l');<br>
echo "Content after character 'l':" . $result . \n"; // Output: ld</p>
<p>// Find a non-existent character 'x'<br>
$result2 = strrchr($str, 'x');<br>
var_dump($result2); // bool(false)</p>
<p>/**</p>
<ul>
<li>
<p>3. Usage Notes</p>
</li>
<li>
<ul>
<li>
<p>strrchr() is case-sensitive.</p>
</li>
</ul>
</li>
<li>
<ul>
<li>
<p>For case-insensitive searches, use strripos() to get the position and then manually extract the substring.</p>
</li>
</ul>
</li>
<li></li>
<li>
<ol start="4">
<li>
<p>Combined Example: Getting File Extension<br>
*/</p>
</li>
</ol>
</li>
</ul>
<p>$filename = "example.document.pdf";<br>
$extension = strrchr($filename, '.');<br>
echo "The file extension is: " . $extension . \n"; // Output: .pdf</p>
<p>/**</p>
<ul data-is-last-node="" data-is-only-node="">
<li>
<p>5. Summary</p>
</li>
<li>
<p>strrchr() is a convenient and quick string function, often used to extract the last occurrence of a character and everything after it.</p>
</li>
<li data-is-last-node="">
<p data-is-last-node="">It is useful for quickly getting paths, file extensions, or content after punctuation.<br>
*/<br>
?><br>
</span>