php Wordwrap示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Wordwrap示例相关的知识,希望对你有一定的参考价值。

<span style="color: #808080; font-style: italic;">// create a long text for testing:</span>
<span style="color: #0000ff;">$long_text</span> = <span style="color: #ff0000;">'This is a long text to demonstrate the usage of the '</span>;
<span style="color: #0000ff;">$long_text</span> .= <span style="color: #ff0000;">'wordwrap function. '</span>;
<span style="color: #0000ff;">$long_text</span> .= <span style="color: #ff0000;">'Fooooooooooooooooobar, just fooling around'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// syntax: wordwrap(input string, line max. width, break chars, cut words)</span>
<span style="color: #0000ff;">$new_text</span> = <a href="http://www.php.net/wordwrap"><span style="color: #000066;">wordwrap</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$long_text</span>, <span style="color: #cc66cc;">15</span>, <span style="color: #ff0000;">&quot;&lt;br/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$new_text</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/* 
The output will be:
&nbsp;
This is a long&lt;br/&gt;
text to&lt;br/&gt;
demonstrate the&lt;br/&gt;
usage of the&lt;br/&gt;
wordwrap&lt;br/&gt;
function.&lt;br/&gt;
Foooooooooooooo&lt;br/&gt;
ooobar, just&lt;br/&gt;
fooling around
&nbsp;
*/</span>

以上是关于php Wordwrap示例的主要内容,如果未能解决你的问题,请参考以下文章

UTF-8 的多字节安全 wordwrap() 函数

优化 WordWrap 算法

wordwrap 一个很长的字符串

wordwrap — 打断字符串为指定数量的字串

wordwrap — 打断字符串为指定数量的字串

QT Text.WordWrap 在 ColumnLayout 中不起作用