Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / PHP

str_ends_with()

Verifica um sufixo de bytes exato sem o extrair e distingue maiúsculas.

Versão: PHP 8.4; repository runtime, production runtime not attested

Sintaxe

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

Verifica um sufixo de bytes exato sem o extrair e distingue maiúsculas. Um padrão mais longo falha e um vazio corresponde sempre. Para extensões sem distinção de maiúsculas normalize explicitamente antes do teste.

Assinatura

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

Saída do exemplo

[true,false,false,true]

Exemplos

<?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]

Fontes