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 line using PHP?
views:
39answers:
2
+3
A:
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:
deceze
2010-06-30 01:39:23
but does it count white-space?
pOp
2010-06-30 01:41:11
@pOp Yes, look at the examples.
deceze
2010-06-30 01:44:34
Unless you are after something a lot more specific that isn't described above, wordwrap will do everything you need it to do.
Valorin
2010-06-30 05:44:15
A:
Try chunk_split() if you don't mind cutting words in half. It treats whitespace as any other char.
Kamil Szot
2010-06-30 01:46:24