5个字符后自动换行

Rob*_*ion 2 php

伙计们我只想问是否有可能:例如,$currenttext = "someexamplepls"; 如果您想要显示或打印它只是使用,print "$currenttext";那么准备好的输出看起来像这样someexamplepls.我的问题是,如果我想像这样打印它:

somee
xampl
epls
Run Code Online (Sandbox Code Playgroud)

在每5个字符中都有自动换行符我该怎么办?

Thi*_*ter 9

用途wordwrap():

echo wordwrap($str, 5, "\n", true);
Run Code Online (Sandbox Code Playgroud)

如果您想要使用HTML换行符<br>而不是\n.