An ongoing series of characters in a string, how do I split it in a specific place, e.g. 30 characters in php

I am trying to split / split an ongoing series of characters in a php string at a specific point e.g.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 

to

 AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA 
0
source share
3 answers

PHP has a chunk_split() function that does exactly what you ask ...

 $myLongString = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; $splitString = chunk_split($myLongString, 20); echo $splitString; /* AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAA */ 
+2
source

I would use wordwrap () with the $ break parameter as "".

+1
source

Just take a look at the substr function here ..

eg:

 substr('foobar', 0, 3). ' '; 

gives

 'foo ' 
0
source

All Articles