Re: Formatting in Text Area
| From: | Tobias Franzén | Date: | Fri, 01 Feb 2008 15:24:34 +0000 |
| Subject: | Re: Formatting in Text Area | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-44559@lists.php.net to get a copy of this message | ||
Hi Patricia,
You can impose width restrictions on the textarea field and forcefully
wrap lines longer than the desired length afterwards (if you save it,
save it as-is for better portability). To wrap text with PHP when you
print it, or want to send the e-mail, there is a function called
wordwrap(). Be sure to split the string at every line break though.
Using white-spaces for formating will only work if your output of the
text is with a fixed-width font. The <pre> html tag will do this for
you, but it won't look pretty. Use CSS to style it is my advise.
Something to bear in mind with regards to e-mail is that the "standard"
line width is 72 characters if I remember correctly.
Comparison of fixed-width fonts
http://www.cfcl.com/vlb/h/fontmono.html
Example code (not tested, so I'm not sure it will run as-is):
<?php
$text = $_POST["textareainput"];
$long_lines = split("\n", $text);
$split_text = "";
$width = 72;
foreach ($long_lines as $oneline) {
$split_text = $split_text . wordwrap($oneline, $width, "\n") . "\n";
}
// $split_text will have one more newline at the end than what you
started with, so let's clean it up
$split_text = substr($split_text, 0, -1);
echo "<pre>" . $split_text . "</pre>";
// or
echo nl2br($split_text);
?>
/Tobias
VanBuskirk, Patricia wrote:
Sorry, I had sent this first to my FileMaker list, but then realized it was probably more html/php related than database related. FMP is for FileMaker Pro. Can you give me an example of your suggestion? I am still quite new at php and learn much better by example. Thanks Evert! Trish -----Original Message----- From: Evert Lammerts [mailto:evert.lammerts@gmail.com] Sent: Friday, February 01, 2008 8:21 AM To: VanBuskirk, Patricia Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Formatting in Text Area VanBuskirk, Patricia wrote:I have a "customer description" text area field on my form which feedsthrough php to FMP, What's FMP? Is that what links this email to the db-list?and spits out a confirmation page and email. The issue I am havingis this ... as the customer types, the text wraps. Many put their own hard returns and spaces in to organize their description. It seems I can't get it to do both the wrap and show the actual formatting entered. If I format the field as physical wrap, the lines run off the page on the confirmation/printout. If I format it as virtual, then the hard returns, etc get lost. I have also tried using <PRE> on the confirmation page and email and that doesn't work either.Line wrapping in a text area is a property of the text area, not of the text, as opposite to line breaks and hard returns. This is why you won't find line break characters at the place the text used to wrap in the text area. What you can do of course is to add a div (or whatever container you feel like) of the same width / height as the text area to the confirmation page and replace \l\r with br 's.