views:

41

answers:

3

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.

A: 

by any chance are the spaces in this long string   eg. non breaking spaces? If so then just replace them with normal spaces.

if not then please show us some of this html that is generated and the code that generates it.

Adam Butler
A: 

I think PHP's nl2br-function is what you are looking for. It converts any linebreaks (\n) into html-breaks (<br />). Alternatively, you could take a look at the white-space CSS command.

elusive
+3  A: 

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.

robertc
Thank you! word-wrap was what I needed.
serv-bot 22