[lang-ref] ( remove_suffix ) ( php )
<?php
public function testRemoveSuffixAlternative(): void
{
// not built-in
function removeSuffix(string $text, string $suffix): string
{
if ($suffix !== '' && str_ends_with($text, $suffix)) {
return substr($text, 0, strlen($text) - strlen($suffix));
}
return $text;
}
$text = 'abcdefghijk';
$suffix = 'ijk';
$this->assertSame('abcdefgh', removeSuffix($text, $suffix));
}