开发者

How to count characters including white space and then break onto a new line after a certain length using PHP

开发者 https://www.devze.com 2023-01-05 17:16 出处:网络
How to count characters including white space and then break after a certain length for instance how would i break a string after 25 characters onto a new li开发者_开发问答ne using PHP? Fortunately so

How to count characters including white space and then break after a certain length for instance how would i break a string after 25 characters onto a new li开发者_开发问答ne using PHP?


Fortunately somebody's already done the work. Use wordwrap.


If you really want to reinvent the wheel for learning sake, here are a few pieces to get you started:

  • for (...) { }
  • strlen()
  • $str[$x] to access character x of string $str
  • %
  • .


Try chunk_split() if you don't mind cutting words in half. It treats whitespace as any other char.

0

精彩评论

暂无评论...
验证码 换一张
取 消