StringUtil
class StringUtil extends Text
CEO String utilities
None of these should be considered cryptographically secure. Yo.
Methods
Determine if passed string is a UUIDv4
Generate a (hopefully) unique, time-based UUID
Generate random string of a fixed length. Only uses alpha-numeric characters.
Parse a SRN into its component parts. Returns an array with: * client * appid * resource * uuid * extra
Generate slugs
Run dirty html fragments through the purifier
Generate a relatively random token of a given length.
Details
at line line 20
static boolean
isUuid(string $str)
Determine if passed string is a UUIDv4
at line line 30
static string
uuid()
Generate a (hopefully) unique, time-based UUID
at line line 42
static string
random($length = 25, $prefix = '', $type = null)
Generate random string of a fixed length. Only uses alpha-numeric characters.
at line line 78
static array
parseSrn(string $srn)
Parse a SRN into its component parts. Returns an array with: * client * appid * resource * uuid * extra
Example:
use Ceo\Core\Util\String; var_export(String::parseSrn('srn:tsn:ceo-core/user:ec3f361b-6ca7-4d97-8970-099ea4b19419'));
Would give you:
[ 'client' => 'tsn', 'appid' => 'ceo-core', 'resource' => 'user', 'uuid' => 'ec3f361b-6ca7-4d97-8970-099ea4b19419', 'extra' => '' ]
at line line 114
static string
sluggify($str, $delim = '-')
Generate slugs
at line line 136
static string
htmlPurify(string $str)
Run dirty html fragments through the purifier
In theory, is HTML5 compliant
at line line 155
static string
generateToken(int $length = 10)
Generate a relatively random token of a given length.
THIS IS NOT CRYPTOGRAPHICALY SECURE and don't use it for that purpose. You're going to have a bad time.
Based on (https://stackoverflow.com/a/1516430) but improved for randomness and security.