mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
first
This commit is contained in:
32
src/Support/Str.php
Normal file
32
src/Support/Str.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Str
|
||||
{
|
||||
/**
|
||||
* Checks if the given `$target` starts with the given `$search`.
|
||||
*/
|
||||
public static function startsWith(string $target, string $search): bool
|
||||
{
|
||||
return substr($target, 0, strlen($search)) === $search;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given `$target` ends with the given `$search`.
|
||||
*/
|
||||
public static function endsWith(string $target, string $search): bool
|
||||
{
|
||||
$length = strlen($search);
|
||||
if ($length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return substr($target, -$length) === $search;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user