用随机值替换空格

replace spaces with randam values

本文关键字:空格 替换 随机      更新时间:2023-09-26

我有一个段落…我想把空格替换成一些随机值。例如

$string="Kapa dim nen ma sibilol sebire rola lunie. "Ifosamac rapieco他总裁vimeror eralerie puredus elacecos tusorop goba oliw gepalar。"

和结果美元= " Kapa [rand2]的[mailingid]欧宁马[rand2] [rand1] sibilol [rand1] [mailingid] sebire [rand1]劳拉[rand2] lunie.Ifosamac [mailingid] rapieco [rand1]他[rand1] [mailingid]总裁[rand1] vimeror [mailingid] eralerie [mailingid] puredus [hashx] elacecos [rand1] tusorop [rand1] [mailingid] goba [rand1] oliw mailingid gepalar。"

其中随机值为"[mailingid],[rand1],[rand2],[hashx]"

请给我PHP代码....

可以使用函数rand():

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

或者你是指列表中的一个随机值?在本例中:

$list = array("value1", "value2");
$str = str_replace(' ', array_rand($list, 1), $str);

最好使用str_replace函数

str_replace(find,replace,string);
ex:- str_replace(' ','/',$string);