webservco /
framework
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace WebServCo\Framework\Helpers; |
||
| 6 | |||
| 7 | class StringHelper |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @param mixed $context |
||
| 11 | */ |
||
| 12 | public static function getContextAsString($context): string |
||
| 13 | { |
||
| 14 | \ob_start(); |
||
| 15 | \var_dump($context); |
||
|
0 ignored issues
–
show
Security
Debugging Code
introduced
by
Loading history...
|
|||
| 16 | return (string) \ob_get_clean(); |
||
| 17 | } |
||
| 18 | |||
| 19 | public static function isEmpty(string $string): bool |
||
| 20 | { |
||
| 21 | if ('' === $string) { |
||
| 22 | return true; |
||
| 23 | } |
||
| 24 | |||
| 25 | return false; |
||
| 26 | } |
||
| 27 | |||
| 28 | public static function linkify(string $string): string |
||
| 29 | { |
||
| 30 | return (string) \preg_replace( |
||
| 31 | "~[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]~", |
||
| 32 | "<a href=\"\\0\">\\0</a>", |
||
| 33 | $string, |
||
| 34 | ); |
||
| 35 | } |
||
| 36 | |||
| 37 | public static function startsWith(string $haystack, string $needle, bool $ignoreCase = true): bool |
||
| 38 | { |
||
| 39 | if (false !== $ignoreCase) { |
||
| 40 | $function = \function_exists('mb_stripos') |
||
| 41 | ? 'mb_stripos' |
||
| 42 | : 'stripos'; |
||
| 43 | } else { |
||
| 44 | $function = \function_exists('mb_strpos') |
||
| 45 | ? 'mb_strpos' |
||
| 46 | : 'strpos'; |
||
| 47 | } |
||
| 48 | |||
| 49 | return 0 === $function($haystack, $needle); |
||
| 50 | } |
||
| 51 | } |
||
| 52 |