问题
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
回答1:
PHP has a function called chunk_split() which does exactly what you ask...
$myLongString = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
$splitString = chunk_split($myLongString, 20);
echo $splitString;
/*
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
*/
回答2:
I would use wordwrap() with the $break parameter as " ".
回答3:
Just take a look at substr
function here..
eg:
substr('foobar', 0, 3). ' ';
yields
'foo '
来源:https://stackoverflow.com/questions/4348892/a-continues-series-of-characters-in-a-string-how-do-i-split-it-at-a-certain-poin