public static function endsWith($string, $end) { // Needle cannot be found if needle is longer than haystack. if (($offset = strlen($string) - strlen($end)) >= 0) { return strpos($string, $end, $offset) === $offset; } return false; }
public function testEndsWith() { self::assertTrue(StringType::endsWith('foo', 'oo')); self::assertTrue(StringType::endsWith('foo', 'foo')); self::assertFalse(StringType::endsWith('foo', 'f')); self::assertFalse(StringType::endsWith('f', 'foo')); }