2024-03-27 21:04:19 +01:00
|
|
|
<?php
|
|
|
|
|
2024-03-28 22:13:13 +01:00
|
|
|
function createUUID()
|
2024-03-27 21:04:19 +01:00
|
|
|
{
|
2024-03-28 22:13:13 +01:00
|
|
|
if (function_exists('com_create_guid') === true) {
|
|
|
|
return trim(com_create_guid(), '{}');
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(
|
|
|
|
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
|
|
|
|
mt_rand(0, 65535),
|
|
|
|
mt_rand(0, 65535),
|
|
|
|
mt_rand(0, 65535),
|
|
|
|
mt_rand(16384, 20479),
|
|
|
|
mt_rand(32768, 49151),
|
|
|
|
mt_rand(0, 65535),
|
|
|
|
mt_rand(0, 65535),
|
|
|
|
mt_rand(0, 65535)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function safeString($string)
|
|
|
|
{
|
|
|
|
return strtolower(
|
|
|
|
trim(
|
|
|
|
preg_replace(
|
|
|
|
'~[^0-9a-z]+~i',
|
|
|
|
'_',
|
|
|
|
html_entity_decode(
|
|
|
|
preg_replace(
|
|
|
|
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i',
|
|
|
|
'$1',
|
|
|
|
htmlentities($string, ENT_QUOTES, 'UTF-8')
|
|
|
|
),
|
|
|
|
ENT_QUOTES,
|
|
|
|
'UTF-8'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'-'
|
|
|
|
)
|
|
|
|
);
|
2024-03-27 21:04:19 +01:00
|
|
|
}
|
2024-04-16 23:36:57 +02:00
|
|
|
|
|
|
|
function randomString(int $length)
|
|
|
|
{
|
|
|
|
$alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
$special = '*&!@%^#$';
|
|
|
|
$alphabet = $alphanum . $special;
|
|
|
|
$random = openssl_random_pseudo_bytes($length);
|
|
|
|
$alphabet_length = strlen($alphabet);
|
|
|
|
$string = '';
|
|
|
|
for ($i = 0; $i < $length; ++$i) {
|
|
|
|
$string .= $alphabet[ord($random[$i]) % $alphabet_length];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
2024-06-25 23:33:42 +02:00
|
|
|
|
|
|
|
function delete_directory($dirPath)
|
|
|
|
{
|
|
|
|
if (is_dir($dirPath)) {
|
|
|
|
$objects = new DirectoryIterator($dirPath);
|
|
|
|
foreach ($objects as $object) {
|
|
|
|
if (!$object->isDot()) {
|
|
|
|
if ($object->isDir()) {
|
|
|
|
delete_directory($object->getPathname());
|
|
|
|
} else {
|
|
|
|
unlink($object->getPathname());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rmdir($dirPath);
|
|
|
|
} else {
|
|
|
|
throw new Exception(__FUNCTION__ . '(dirPath): dirPath is not a directory!');
|
|
|
|
}
|
|
|
|
}
|