我有一个字符串
$str = 'aaaaabbbbbcccccdddddeeeeefffffggggghhhhhjjjjj';
$pos = 0;
$tmp = 0;
while($pos<strlen($str)) {
$tmp .= substr($str,$pos,5)."\n";
$pos += 5;
}
我不想在制作"\n"
$str
aaaaa
bbbbb
ccccc
ddddd
eeeee
fffff
ggggg
hhhhh
jjjjj //No new line here
答案 0 :(得分:3)
echo join("\n", str_split($string, 5));
答案 1 :(得分:1)
while($pos<strlen($str)) {
if ($pos > 0) $tmp .= "\n";
$tmp .= substr($str,$pos,5);
$pos += 5;
}
答案 2 :(得分:0)
一种方法是在while循环之后对换行进行索引