$q = ',q, w, r,';
<span>q</span> <span>w</span> <span>r</span>
$q = ',q,w,e,';
$numbers = array_slice(explode(',', trim($q, ',')), 0, 10);
foreach($numbers as $key => $d) {
$value = '<span>'.$d.'</span>';
}
echo $value;
echo implode(' ', array_map(function($d) {
return '<span>'.trim($d).'</span>';
}, explode(',', trim($q, ','))));