21 lines
510 B
Plaintext
21 lines
510 B
Plaintext
|
/**
|
||
|
* Making class or function name safe
|
||
|
*
|
||
|
* @input string The name you would like to make safe
|
||
|
*
|
||
|
* @returns string on success
|
||
|
*
|
||
|
* @since 3.0.9
|
||
|
*/
|
||
|
public static function safe($name): string
|
||
|
{
|
||
|
// remove numbers if the first character is a number
|
||
|
if (is_numeric(substr((string) $name, 0, 1)))
|
||
|
{
|
||
|
$name = StringHelper::numbers($name);
|
||
|
}
|
||
|
|
||
|
// remove all spaces and strange characters
|
||
|
return trim(preg_replace("/[^A-Za-z0-9_-]/", '', (string) $name));
|
||
|
}
|