开发者

Split string every 80 characters in PHP

I'm pulling data from a mainframe. I have this long string. I need to make a print view of this string. If I split it every 80 characters it will format correctly (since that's how it's开发者_C百科 chopped up on the mainframe screen). By splitting I mean inserting an end of line or a break in the view.

The code is simple:

$string = "A big long string that needs to be chopped every 80 chars";


Use the following:

chunk_split ( $string, 80 );

There's a 3rd parameter, used to set the separator. By default, this is a platform-specific end-of-line.

This is probably faster than wordwrap since it doesn't take care of words at all.


Try the wordwrap function.


Use wordwrap(): http://php.net/manual/en/function.wordwrap.php

wordwrap($string, 80, "\n", true);

Substitute <br> for \n depending on your needs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜