public static function SchemaMetatagManager::randomString in Schema.org Metatag 8
Same name and namespace in other branches
- 8.2 src/SchemaMetatagManager.php \Drupal\schema_metatag\SchemaMetatagManager::randomString()
Generates a pseudo-random string of ASCII characters of codes 32 to 126.
Parameters
int $length: Length of random string to generate.
Return value
string Pseudo-randomly generated unique string including special characters.
Overrides SchemaMetatagManagerInterface::randomString
File
- src/
SchemaMetatagManager.php, line 321
Class
- SchemaMetatagManager
- Class SchemaMetatagManager.
Namespace
Drupal\schema_metatagCode
public static function randomString($length = 8) {
$randomGenerator = new Random();
if ($length < 4) {
return $randomGenerator
->string($length, TRUE);
}
// Swap special characters into the string.
$replacement_pos = floor($length / 2);
$string = $randomGenerator
->string($length - 2, TRUE);
return substr_replace($string, '>&', $replacement_pos, 0);
}