开发者

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

开发者 https://www.devze.com 2023-01-28 14:31 出处:网络
I\'m trying to break/split a continues series of characters in a php string at a specific point e.g. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

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

精彩评论

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