-5

段落があります。スペースをいくつかのランダムな値に置き換えたいです。例えば

$ string = "Kapa dim nen ma sibilol sebirerolalunie。Ifosamacrapiecohim oku、vimeror eralerie puredus elacecos tusorop gobasoliwgepalar。"

および$result= "Kapa [rand2] dim [mailingid] nen [rand2] ma [rand1] sibilol [rand1] [mailingid] sebire [rand1] rola [rand2] lunie.Ifosamac [mailingid] rapieco [rand1] him [rand1] [mailingid] oku、[rand1] vimeror [mailingid] eralerie [mailingid] puredus [hashx] elacecos [rand1] tusorop [rand1] [mailingid] gobas [rand1] oliw[mailingid]gepalar。」

ここで、ランダム値は「[mailingid]、[rand1]、[rand2]、[hashx]」です。

PHPコードを教えてください...。

4

2 に答える 2

1

str_replace関数を使用することをお勧めします。

str_replace(find,replace,string);

ex:- str_replace(' ','/',$string);
于 2013-01-18T11:06:41.107 に答える
1

あなたは関数を使うことができますrand()

$str = str_replace(' ', rand(0, 10000), $str);

それとも、リストからランダムな値を意味しましたか?この場合:

$list = array("value1", "value2");
$str = str_replace(' ', array_rand($list, 1), $str);
于 2013-01-18T11:09:19.563 に答える