First, if you want the text to be as wide as possible, attach all this to the wrapping <div> element and use CSS for its maximum width. Any text inside an element followed by a wrapper.
Here is the CSS code you need:
#mydiv {width:200px;}
The only text that will still be the problem after this is the text without any spaces in it, which will still stretch from the edge of the page.
For this you can use another CSS property, word-wrap , for example:
#mydiv {word-wrap:break-word;}
The best practice is to keep the CSS code separate from your HTML, but if you are not using style sheets, you can add CSS code directly to the <div> element with the style attribute, for example:
<div style='width:200px; word-wrap:break-word;'> ..... (your content goes here) ..... </div>
Of course, it is possible to do word wrap in PHP using the wordwrap() (or str_split() function for long lines without spaces), but in the end you will have lines having different lengths when displayed on the page, because the font has different widths for different characters. Therefore, I would say that CSS solution is better, because the packaging of words will look better on the page.
Hope this helps.
source share