CKTIS / PHP
str_ends_with()
Comprueba un sufijo de bytes exacto sin extraerlo y distingue mayúsculas.
Versión: PHP 8.4; repository runtime, production runtime not attested
Sintaxis
str_ends_with(string $haystack, string $needle): boolComprueba un sufijo de bytes exacto sin extraerlo y distingue mayúsculas. Una aguja más larga falla y una vacía siempre coincide. Para extensiones sin distinguir mayúsculas normaliza explícitamente antes de probar.
Firma
str_ends_with(string $haystack, string $needle): bool
Salida del ejemplo
[true,false,false,true]
Ejemplos
<?php
echo json_encode([str_ends_with("note.txt",".txt"),str_ends_with("note.TXT",".txt"),str_ends_with("x","xx"),str_ends_with("x","")]);
Resultado
[true,false,false,true]