我想每五个单词后分割一个字符串。
例子
这里有一些东西要输入。这是示例文本
输出
There is something to type
here. This is an example
text
Run Code Online (Sandbox Code Playgroud)
如何使用 来完成此操作preg_split()?或者有什么方法可以在 PHP GD 中进行文本换行吗?
您也可以使用正则表达式
$str = 'There is something to type here. This is an example text';
echo preg_replace( '~((?:\S*?\s){5})~', "$1\n", $str );
Run Code Online (Sandbox Code Playgroud)
这里有一些东西要输入
。这是示例
文本
| 归档时间: |
|
| 查看次数: |
5234 次 |
| 最近记录: |