-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 に答える