[lang-ref] ( string_ends_with ) ( php )
<?php
public function testStringEndsWith(): void
{
// str_ends_with($text, $suffix)
// PHP 8+
$text = 'Good morning';
$s = 'ing';
$this->assertTrue(str_ends_with($text, $s));
}
<?php
public function testStringEndsWithAlternative(): void
{
// substr(...) === $s
// for older PHP versions
$text = 'Good morning';
$s = 'ing';
$endsWith = ($s === '') || (substr($text, -strlen($s)) === $s);
$this->assertTrue($endsWith);
}