The "startsWith" function in PHP checks if a string begins with the specified suffix. It returns a boolean value- true if the string starts with the specified suffix and false otherwise.
Example 1:
$string = "Hello World"; $suffix = "Hello"; if (startsWith($string, $suffix)) { echo "The string starts with the suffix."; } else { echo "The string does not start with the suffix."; }
This code will output "The string starts with the suffix." because the $string variable starts with the specified $suffix.
Example 2:
$string = "This is a sample string"; $suffix = "sample"; if (startsWith($string, $suffix)) { echo "The string starts with the suffix."; } else { echo "The string does not start with the suffix."; }
This code will output "The string does not start with the suffix." because the $string variable does not start with the specified $suffix.
The "startsWith" function is a built-in function in PHP and does not require any external package or library.
PHP String::startsWith - 29 examples found. These are the top rated real world PHP examples of String::startsWith from package spaghettiphp extracted from open source projects. You can rate examples to help us improve the quality of examples.