strchr() : finding substrings and extracting parts of strings

strchr(string $haystack, mixed $needle, bool $before_needle = false): string|false
Returns the substring starting from the match point onwards, or returns FALSE if no match is found in the string.

strchr() function in PHP performs a case-sensitive search to find the first occurrence of a specified character in a string. If you need a case-insensitive search, you might use stristr() instead.

Example 1: Basic Usage

Find the first occurrence of "world" in the string.
$text = "Hello world, the world is great!";
$result = strchr($text, "world");
echo $result;
world, the world is great!

Example 2: Using the before_needle Parameter

Return part of the string before the first occurrence of "world".
$text = "Hello world, the world is great!";
$result = strchr($text, "world", true);
echo $result;
Output
Hello 

Example 3: Case-Sensitive Search

Searching for "World" will not match "world" due to case sensitivity.
$text = "Hello world, the world is great!";
$result = strchr($text, "World");
echo $result ? 'True':'False';
Output
False

String Functions chunk_split(): Split a string into smaller chunks
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer