Statement on glibc/iconv Vulnerability

str_starts_with

(PHP 8)

str_starts_withChecks if a string starts with a given substring

Descripción

str_starts_with(string $haystack, string $needle): bool

Performs a case-sensitive check indicating if haystack begins with needle.

Parámetros

haystack

The string to search in.

needle

The substring to search for in the haystack.

Valores devueltos

Returns true if haystack begins with needle, false otherwise.

Ejemplos

Ejemplo #1 Using the empty string ''

<?php
if (str_starts_with('abc', '')) {
echo
"All strings start with the empty string";
}
?>

El resultado del ejemplo sería:

All strings start with the empty string

Ejemplo #2 Showing case-sensitivity

<?php
$string
= 'The lazy fox jumped over the fence';

if (
str_starts_with($string, 'The')) {
echo
"The string starts with 'The'\n";
}

if (
str_starts_with($string, 'the')) {
echo
'The string starts with "the"';
} else {
echo
'"the" was not found because the case does not match';
}

?>

El resultado del ejemplo sería:

The string starts with 'The'
"the" was not found because the case does not match

Notas

Nota: Esta función es segura binariamente.

Ver también

  • str_contains() - Determine if a string contains a given substring
  • str_ends_with() - Checks if a string ends with a given substring
  • stripos() - Encuentra la posición de la primera aparición de un substring en un string sin considerar mayúsculas ni minúsculas
  • strrpos() - Encuentra la posición de la última aparición de un substring en un string
  • strripos() - Encuentra la posición de la última aparición de un substring insensible a mayúsculas y minúsculas en un string
  • strstr() - Encuentra la primera aparición de un string
  • strpbrk() - Buscar una cadena por cualquiera de los elementos de un conjunto de caracteres
  • substr() - Devuelve parte de una cadena
  • preg_match() - Realiza una comparación con una expresión regular

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top