-1

我正在尝试制作一个脚本,该脚本将从字符列表中获取随机变量。我+ &之前的每封信。这是我到目前为止想出的

<form action="#" method="post">
  <input type="text" name="text">
  <input type="submit" name="submit">
</form>

<?php
  if (isset($_POST['submit'])) {
    $str = $_POST["text"];

    $arr1 = str_split($str);



   foreach ($arr1 as $value)
   {
     $length = 1; 
     $chars = '46eab95'; 
     $charslength = strlen($chars); 
     $randomstring = ''; 
     for ($i = 0; $i < $length; $i++) $randomstring .= substr($chars, rand(0, $charslength - 1), 1); 
       echo $randomstring;  
       echo "&" . $randomstring . $value;
     }
   }
?>

但它只是搞砸了,无法工作,例如,当我试图让它做时,你好,结果是这样的: 6&6h4&4e4&4l6&6l5&5o

4

1 回答 1

1

稍微改写一下——这对你有用吗?

<?php
$str = "hello";
$arr1 = str_split($str);

foreach ($arr1 as $value)
{
    $chars = '46eab95'; 
    $chars = str_split($chars);

    $randomstring = ''; 
    foreach ($arr1 as $char)
    {
        $randomstring .= "&" . $chars[array_rand($chars)] . $char;
    }
}

echo $randomstring; //&bh&ee&4l&9l&eo
于 2012-12-09T09:49:40.930 回答