开发者

A continues series of characters in a string how do I split it at a certain point e.g 30 charaacters in php

I'm trying to break/split a continues series of characters in a php string at a specific point e.g.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

to

AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA开发者_开发技巧


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

$myLongString = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';

$splitString = chunk_split($myLongString, 20);

echo $splitString;

/*

AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA

*/


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


Just take a look at substr function here..

eg:

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

yields

'foo '
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜