Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  164] [ 6]  / answers: 1 / hits: 18270  / 12 Years ago, sat, march 10, 2012, 12:00:00

What if I have a long input of string? maybe 50-250 characters.
and I echoed the variable it would echo a very long line of letters and words.



So, how will I let the variable auto Newline itself? maybe after 50 characters it would new line when echoed.



I have thought of counting the length of the string and looping it and after counting 50 characters it would Newline but if i do that it would slow down the Site.



is there any function to Newline a VARIABLE STRING? or i should use Looping instead?


More From » php

 Answers
36

You can use a built-in PHP function: wordwrap.



If you want to cut at 50 characters and insert a HTML line-break:
wordrap($str, 50, <br />);
You can also use the last parameter to force return, even if the string does not contain spaces.


[#86937] Friday, March 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
prestonh

Total Points: 384
Total Questions: 105
Total Answers: 105

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
;