$ri8 = count(explode('<随机3数>', $moban)) - 1; for ($i = 0; $i < $ri8; $i++) { $moban = preg_replace('/<随机3数>/', mt_rand(111, 999), $moban, 1); }