for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace FondBot\Helpers;
class Str
{
/**
* Determine if a given string contains a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*/
public static function contains(string $haystack, $needles)
foreach ((array) $needles as $needle) {
if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
return true;
}
return false;
* Determine if a given string ends with a given substring.
public static function endsWith(string $haystack, $needles): bool
if (substr($haystack, -strlen($needle)) === (string) $needle) {
* Generate a more truly "random" alpha-numeric string.
* @param int $length
* @return string
public static function random(int $length = 16): string
$string = '';
while (($len = strlen($string)) < $length) {
$size = $length - $len;
$bytes = random_bytes($size);
$string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
return $string;
* Convert the given string to lower-case.
* @param string $value
public static function lower($value)
return mb_strtolower($value, 'UTF-8');