0
例如:将随机字符转换成字符串
$myString = "Hello World";
我希望把随机字符到它,所以它变成是这样的:
$myString = "[email protected]#llo$*Wo-rld+";
感谢
例如:将随机字符转换成字符串
$myString = "Hello World";
我希望把随机字符到它,所以它变成是这样的:
$myString = "[email protected]#llo$*Wo-rld+";
感谢
天真的算法:
$len=strlen($myString); // we will not recalc it
$allowed=array('!','~');
for(int $i=0;$i<$countOfChars;++i){
$x=rand(0,$len); //put after $x characters;
$char=$allowed[array_rand($allowed)];
$myString=substr($myString,0,$x).$char.substr($myString,$x);
++$len;
}
但是我认为你应该忘记这个想法,并以其他方式解决你的问题
感谢它工作:) – Muazam
好的,有很多方法可以做到这一点,但为什么? – Gerry
@Gerry只是做一个新手加密。请帮助我:) – Muazam
嗯,看看这个例子,如何做一次,然后你只需要在一个循环中运行你想插入的字符数:http://stackoverflow.com/questions/6503176/php-how-to-add-a-random-character-in-a-string-at-random-position – Gerry