startsWith() and endsWith() functions in PHP
Asked 07 September, 2021
Viewed 2.4K times
  • 58
Votes

How can I write two functions that would take a string and return if it starts with the specified character/string or ends with it?

For example:

$str = '|apples}';

echo startsWith($str, '|'); //Returns true
echo endsWith($str, '}'); //Returns true

30 Answer