a method of selecting random characters from given string

前端 未结 15 1976
小鲜肉
小鲜肉 2020-12-03 21:53

Can anyone help me with a solution that pulls the position and value of a random character from a given string using PHP. For example I have a a string variable $string = \

15条回答
  •  感动是毒
    2020-12-03 22:12

    Since noone mentinoned any utf8 (multibyte) safe method, here is mine:

    mb_internal_encoding("UTF-8");
    $possible="aábcdeéfghiíjklmnoóöópqrstuúüűvwxyzAÁBCDEÉFGHIÍJKLMNOÓÖŐPQRSTUÚVWXYZ";
    $char=mb_substr($possible,rand(0, mb_strlen($possible) - 1),1);
    

提交回复
热议问题