30 seconds of PHP

  Back to Home

startsWith

stringbeginner

Check if a string starts with a given substring.

Use strpos() to find the position of $needle in $haystack.

function startsWith($haystack, $needle)
{
  return strpos($haystack, $needle) === 0;
}