for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Core\Traits;
/**
* a trait with some string related helpers
* Trait StringFunctions
* @package Core\Traits
*/
trait StringFunctions
{
* does a haystack start with a needle ?
* @param $haystack string the string to search in
* @param $needle string the string to search for
* @return bool
public function startsWith(string $haystack, string $needle): bool
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
* Does a haystack end with a needle
public function endsWith(string $haystack, string $needle): bool
if ($length == 0) {
return true;
return (substr($haystack, -$length) === $needle);
* Remove the tail of a string
* @param $string string to slice apart
* @param $tail string the string to remove
* @return string
public function removeFromEnd(string $string, string $tail): string
if ($this->endsWith($string, $tail)) {
$string = substr($string, 0, -strlen($tail));
return $string;