If * is your only format character, try converting * to %s (also open the existing % to %% ), and then use vsprintf() , which takes an array of values ββas format parameters:
$str = str_replace(array('%', '*'), array('%%', '%s'), $str); $newstr = vsprintf($str, $arr); echo $newstr;
Output:
abc123efg456hij789
Please note that if you have more array elements than asterisks, additional elements at the end simply will not appear on the line. If you have more stars than array elements, vsprintf() will issue a warning and return too few false arguments.
source share