I basically want to automatically add line breaks to a VARCHAR variable I acquire from a mysql database trough PHP, so that it shows right. At the moment when I show it trough HTML, all it does is give me a long sentence.
I imagine this can be done with CSS, but overflow: scroll
just makes it scroll to the right and left. Use of javascript or JQuery is also accepted.
If it really is a long string with no spaces or line breaks then the word-wrap
CSS property can be set to break-word
. There are some examples on the MDC page. But, like others have said, if this is a normal sentence with spaces in it then a browser will wrap it automatically providing it's not in a pre
block. If its plain text with line breaks that you want preserved then you can either convert the \n
to <br>
like elusive suggested, or just place it in a pre
block to preserve its text formatting.