我需要逻辑或一些具有功能的包来生成具有特定编码的随机字符串,而无需使用基本函数random_bytes等。
就像这样:
$randomLine = random_string($length = 10, $encoding = 'UTF-16');发布于 2018-09-17 12:37:14
如果您有php 7.2+,可以使用mb_chr,如下所示
<?
$max = 10;
$out = '';
$encoding = 'UTF-16';
for ($i = 0;$i<$max;$i++) {
if ($s = mb_chr(rand(1,1114112), $encoding)) {
$out .= $s;
}
}
echo $out;请参阅http://sandbox.onlinephpfunctions.com/code/a4d39412005473231317758ca5d2fc8d4ad0b27b
https://stackoverflow.com/questions/52367634
复制相似问题