Affichage chaîne scindé

Par cid5420, il y a 8 ans


Bonjour,

je cherche à scinder une chaine du type (uniquement pour l'affichage)

1660454395354

en

16 60 45 43 95 35 4

La chaîne est aléatoir et ne contient pas toujours le même nombre de caractère donc voir pour faire des paires... bref si quelqu'un à une idée

4 réponses

Arbiter0x, il y a 8 ans
<?php $str = "166004....."; $arr = str_split($str,2); foreach($arr as $s) { echo $s.' '; } ?>
snapiz, il y a 8 ans
function str_insertChar($str, $size = 1, $char = " ", $ouput = "") { if(($len = strlen($str)) == 0) { return $ouput; } $ouput .= $str[0]; $str = substr($str, 1); if($len >= $size && $len % $size == 0 ) { $ouput .= $char; } return str_insertChar($str, $size, $char, $ouput); } echo str_insertChar("123456789", 2); // 12 34 56 78 9
SimonAndGarfunkel, il y a 8 ans
<?php $str = '1660454395354'; echo implode(' ',str_split($str,2));
cid5420, il y a 8 ans

merci pour vos retour, je comprend pas comment j'ai pue passer à côté :/