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
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











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