Check if a string starts with a given substring.

startsWith
string,beginner
  • Use strpos() to find the position of $needle in $haystack.
function startsWith($haystack, $needle)
{
  return strpos($haystack, $needle) === 0;
}
startsWith('Hi, this is me', 'Hi'); // true

License: CC-0