Text Processing
PHP String Function: Text Processing
function str_starts_with(string $haystack, string $needle)
{
return strpos( $haystack , $needle ) === 0;
}
function str_ends_with(string $haystack, string $needle)
{
$length = strlen($needle);
return $length > 0 ? substr($haystack, -$length) === $needle : true;
}
function str_contains(string $haystack, string $needle)
{
return (strpos($haystack, $needle) !== false);
}
function str_filter_number(string $haystack)
{
$number = str_replace(['+', '-'], '', filter_var($haystack, FILTER_SANITIZE_NUMBER_INT));
return (int) $number;
}
function url($uri): string
{
return sprintf("https://%s%s", $_SERVER['HTTP_HOST'], $uri);
}
$string = 'The string bytes that we want to measure';
echo mb_strlen($string, '8bit');
PHP String Function: Text Processing
PHP String Function: Uuid
PHP String Function: Parse URL
PHP String Function: Regex
PHP String Function: Number