Checking If a String Starts With a Specific Text in PHP


PHP 8 introduced str_starts_with() for this purpose.

Source Code

if (str_starts_with('Hello, World!', 'Hello')) {
    echo "String starts with 'Hello'.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments