This is a working example. bannnnwwe.jpg is here the full filename with the extension, and will print out ban and 3 random numbers, and .jpg in this case. I have tested it, and it works.
$name = "bannnnwwe.jpg";
$number2 = substr($name, 0, 4) .rand(0,1000) .substr($name,-4,4)...