Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert character after each 8 character

i have one string called dvojka value is 0110111101101010 It's a binary. And I need to insert character "-" after each 8 chracter, because one character is 8 bits. Is there some way using PHP? Thank you.

like image 990
René Beneš Avatar asked Jan 17 '23 21:01

René Beneš


1 Answers

wordwrap ?

$output = wordwrap($dvojka,8,'-',true);

The 3rd parameter is required as the string your breaking up doesn't have any whitespace

Example : http://codepad.org/sbhBe5pb

like image 165
Manse Avatar answered Jan 20 '23 11:01

Manse