Reputation: 41
I am developing a forum software for a site.
Anyway, With the description say if I added 100 words it will just go across the page and it will not break down (I want it like this how I moved this to a new line)
I would I make it break down once it gets to the end of the first line or after a certain number of characters.
If it's not possible with CSS how could I do this in PHP then.
Thanks!
Upvotes: 0
Views: 173
Reputation: 201896
If this is simply about limiting the line length, set a maximum width on the element where the text is contained. For example, if the text is inside <p>
element(s), set
p {
max-width: 25em;
max-width: 60ch;
}
This sets the maximum width of any p
element to about 60 characters. (The ch
unit is the width of the digit zero, which is close to an average width of characters, typically. The first declaration is backup setting for browsers that do not support ch
.)
Text will normally wrap at any whitespace character as needed to satisfy the constraint on width.
Upvotes: 0
Reputation: 39
If you take a look at this link:
http://www.php.net/manual/en/function.wordwrap.php
You'll find that this is possible with PHP's string function: wordwrap()
For example:
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");
echo $newtext;
?>
Will output:
The quick brown fox<br />
jumped over the lazy<br />
dog.
See link for more examples: http://www.php.net/manual/en/function.wordwrap.php
Upvotes: 0
Reputation: 1986
using CSS:
try limiting the width of the container div
of the text and add word-wrap
property.
Upvotes: 2
Reputation: 421
You could try this:
$newtext = wordwrap($text, 20, "<br />\n");
Where 20 is the number of characters before the line break.
Upvotes: 0