String

PHP String Function

str_starts_with in PHP7

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

str_ends_with in PHP7

function str_ends_with(string $haystack, string $needle)
{
  $length = strlen($needle);
  return $length > 0 ? substr($haystack, -$length) === $needle : true;
}

str_contains in PHP7

function str_contains(string $haystack, string $needle)
{
  return (strpos($haystack, $needle) !== false);
}

Filter string for everything except number

function str_filter_number(string $haystack)
{
  $number = str_replace(['+', '-'], '', filter_var($haystack, FILTER_SANITIZE_NUMBER_INT));
  return (int) $number;
}

URL

function url($uri): string
{
  return sprintf("https://%s%s", $_SERVER['HTTP_HOST'], $uri);
}

Text Processing

PHP String Function: Text Processing

Uuid

PHP String Function: Uuid

Parse URL

PHP String Function: Parse URL