strchr() Function in PHP 8.2, PHP 8.3, & PHP 8.4


The `strchr()` function in PHP is used to find the first occurrence of a character in a string and returns the portion of the string from that character to the end. It's an alias of the `strstr()` function. PHP 8.PHP 8.1, PHP 8.2,PHP 8.3,and PHP 8.4.

Basic Syntax

<?php
strchr(string $haystack, mixed $needle, bool $before_needle = false): string|false
?>

Parameters
1.`$haystack`: The input string to search in
2.`$needle`: The character to search for (if not a string, it's converted to an integer and used as ASCII value)
3. `$before_needle`: If true, returns the part of the string before the first occurrence

Return Value

Returns the portion of string, or false if needle is not found

Example 1: Basic usage

<?php
$email = 'user@example.com';
$domain = strchr($email, '@');
echo $domain; // Outputs: @example.com
?>

Notes
1. The function is case-sensitive (use `stristr()` for case-insensitive search)
2.In PHP 8.2, this function works the same as in previous versions
3. If you only need to check if a character exists in a string, `strpos()` might be more efficient.