初始化仓库
This commit is contained in:
80
admin/components/UI/yii/Str.php
Normal file
80
admin/components/UI/yii/Str.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/18
|
||||
* Time: 4:14 PM
|
||||
*/
|
||||
|
||||
namespace admin\components\UI\yii;
|
||||
|
||||
class Str
|
||||
{
|
||||
public static function beforeLast($subject, $search)
|
||||
{
|
||||
if ($search === '') {
|
||||
return $subject;
|
||||
}
|
||||
|
||||
$pos = mb_strrpos($subject, $search);
|
||||
|
||||
if ($pos === false) {
|
||||
return $subject;
|
||||
}
|
||||
|
||||
return static::substr($subject, 0, $pos);
|
||||
}
|
||||
public static function substr($string, $start, $length = null)
|
||||
{
|
||||
return mb_substr($string, $start, $length, 'UTF-8');
|
||||
}
|
||||
public static function random($length = 16)
|
||||
{
|
||||
$string = '';
|
||||
|
||||
while (($len = strlen($string)) < $length) {
|
||||
$size = $length - $len;
|
||||
|
||||
$bytes = random_bytes($size);
|
||||
|
||||
$string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
public static function before($subject, $search)
|
||||
{
|
||||
if ($search === '') {
|
||||
return $subject;
|
||||
}
|
||||
|
||||
$result = strstr($subject, (string) $search, true);
|
||||
|
||||
return $result === false ? $subject : $result;
|
||||
}
|
||||
|
||||
public static function contains($haystack, $needles)
|
||||
{
|
||||
foreach ((array) $needles as $needle) {
|
||||
if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public static function afterLast($subject, $search)
|
||||
{
|
||||
if ($search === '') {
|
||||
return $subject;
|
||||
}
|
||||
|
||||
$position = strrpos($subject, (string) $search);
|
||||
|
||||
if ($position === false) {
|
||||
return $subject;
|
||||
}
|
||||
|
||||
return substr($subject, $position + strlen($search));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user