PHP: Insert Random Numbers in Strings

You can use the rand() function to generate random numbers, and then use the substr_replace() function to insert the random number into a random position in the specified string.

Here is an example code:

<?php
function insertRandomNumber($str) {
    $randomNumber = rand(0, 9); // 生成随机数字
    $randomPosition = rand(0, strlen($str)); // 生成随机位置

    // 将随机数字插入到指定字符串的随机位置
    $result = substr_replace($str, $randomNumber, $randomPosition, 0);

    return $result;
}

$str = "Hello World!";
$result = insertRandomNumber($str);

echo $result;
?>

Running the above code will randomly output a number within the specified string.

bannerAds