php 使用wordwrap按照用户指定长度进行换行

前端之家收集整理的这篇文章主要介绍了php 使用wordwrap按照用户指定长度进行换行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
本范例演示了PHP中wordwrap如何按照用户指定的长度进行换行,感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:
  1. /**
  2. * wordwrap如何按照用户指定的长度进行换行
  3. *
  4. * @param
  5. * @arrange (512.笔记) jb51.cc
  6. **/
  7. // create a long text for testing:
  8. $long_text = 'This is a long text to demonstrate the usage of the ';
  9. $long_text .= 'wordwrap function. ';
  10. $long_text .= 'Fooooooooooooooooobar,just fooling around';
  11. // Syntax: wordwrap(input string,line max. width,break chars,cut words)
  12. $new_text = wordwrap($long_text,15,"<br/>\n",true);
  13. print $new_text;
  14. /*
  15. The output will be:
  16. This is a long<br/>
  17. text to<br/>
  18. demonstrate the<br/>
  19. usage of the<br/>
  20. wordwrap<br/>
  21. function.<br/>
  22. Foooooooooooooo<br/>
  23. ooobar,just<br/>
  24. fooling around
  25. */
  26. /*** 代码来自编程之家 jb51.cc(jb51.cc) ***/

猜你在找的PHP相关文章