<?php function replace_num ($num) { $a = array (1 => 'I', 2 => 'II', 3 => 'III', 4 => 'IV', 5 => 'V', 6 => 'VI', 7 => 'VII', 8 => 'VIII', 9 => 'IX'); $b = array(); foreach (explode(',', $num) as $c) $b[] = $a[$c]; return implode(',', $b); } echo replace_num('1,2,3,4,5,6,7,8,9'); ?>