Hi there.
I'm trying to create user comment system that is submitted by form, stored and pulled up by PHP.
And I'm trying to tell the wordwrap() function to wrap sentences when it's longer than 20 characters for output.
But it seems like it's wrapping text wherever it's 20th characters even when it's on the middle of the next line
so the output's alignment looks messy. Some sentences are cut and wrapped in the middle of the sentence.
I want the function to wrap the text around only when it exceeds over 20 characters. Not wherever it gets 20.
Does this make sense?
For example
---Original user's comment----------------------------------
Some loooooooooooong text.
Some loooooooooong text on the second line.
Some looooooooooooooooong text on the third line.
------------------------------------------------------------
//And the comment above will be sent to php script below
PHP Code:
if($_POST['submit'])
{
$someLongText = $_POST['comment'];
$output = wordwrap($someLongText, 20, "<br/>", true); // Telling the text will get wrapped around at 20th character.
$output = str_replace("\r\n","<br/>\r\n",$output); // to preserve line breaks.
}
---- In the file for output-----------------------------------
<body>
<?php $output ?>
</body>
-------------------------------------------------------------
-----------------What you see on a browser------------------------
Some loooooooooooong <---- takes up 20 character spaces
text. <------only takes up 5 character spaces
Some loooooooo <------ this line takes up 15 character spaces. 5+15=20. and it gets cut off in the middle of the sentence..
oong text on the sec
ond line.
Some looooo
oooooooooooong text
on the third line.
-----------------------------------------------------------------
The wordwrap() doesn't care if it finds the 20th letter in the current line or the line below and once it finds the one, it just cut the word off in the middle.)
How can I make the function to wrap up the text only when the number of characters exceed 20 on one line, please?