86 of 410 menu

The str_ends_with Function

The str_ends_with function checks if a string ends with a given substring and returns true on success, and false on failure. The first parameter of the function specifies the string in which to search. The second parameter specifies the desired character or substring.

Syntax

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

Example

Let's check if the string ends with the given character:

<?php $str = 'abcde'; $res = str_ends_with($str, 'e'); var_dump($res); ?>

Code execution result:

true

Example

Let's check if the string ends with the given substring:

<?php $str = 'abcde'; $res = str_ends_with($str, 'de'); var_dump($res); ?>

Code execution result:

true

Example

Let's check if the string ends with the given character:

<?php $str = 'abcde'; $res = str_ends_with($str, 'x'); var_dump($res); ?>

Code execution result:

false

See Also

  • the str_contains function,
    which checks for the occurrence of a character in a string
  • the str_starts_with function,
    which checks the beginning of a string
  • the strrpos function,
    which returns the position of the last occurrence of a substring
  • the strpos function,
    which returns the position of the occurrence of a substring
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline