| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Jfcherng\Diff\Utility; |
| 6 |
|
| 7 |
final class Str |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Determine if a given string starts with a given substring. |
| 11 |
* |
| 12 |
* @param string $haystack the haystack |
| 13 |
* @param string $needle the needle |
| 14 |
*/ |
| 15 |
public static function startsWith(string $haystack, string $needle): bool |
| 16 |
{ |
| 17 |
return substr($haystack, 0, \strlen($needle)) === $needle; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Determine if a given string ends with a given substring. |
| 22 |
* |
| 23 |
* @param string $haystack the haystack |
| 24 |
* @param string $needle the needle |
| 25 |
*/ |
| 26 |
public static function endsWith(string $haystack, string $needle): bool |
| 27 |
{ |
| 28 |
return substr($haystack, -\strlen($needle)) === $needle; |
| 29 |
} |
| 30 |
} |