In theory, this should work:
<?
$oldstring="BLA% BLA% BLA% BLA% BLA%";
list($string1, $string2, $string3, $string4, $string5) = split('[# #e]', $oldstring);
function Loop(){ for($num=1; $num<=5; $num++){
$var = "<input type='text' name='V$num'>";
}
return $var;
}
preg_replace('#%#e', Loop($var), $string1);
preg_replace('#%#e', Loop($var), $string5);
preg_replace('#%#e', Loop($var), $string4);
preg_replace('#%#e', Loop($var), $string3);
preg_replace('#%#e', Loop($var), $string2);
$newstring = $string1.' '.$string2.' '.$string3.' '.$string4.' '.$string5;
echo $newstring;
?>