At 04:15 PM 6/11/2003 -0400, Edward Peloke wrote: Ok,
I am trying to create a very basic page where we can all easily work on a document. I just have a huge textarea that inserts the text into a longtext field in the mysql db. I use nl2br to keep the formatting. Of course, when the document is viewed in the textarea, all of the <br /> are there. THe problem is, everytime I update the text in the textarea, another set of <br />'s are put in so with every edit, the lines get farther and farther apart...why?
Thanks, Eddie
This is a bit of a timing issue - when are you calling nl2br()?
We limited our users to using IE, and have wrap turned ON for the text area.
Articles are written in WordPerfect, then selected and copied to the Windows clipboard, then pasted into the textarea in a stories editing page. This resulted in a lot of "\r\n" cobinations that had to be filtered out, as either the paste operation or the action of copying to the clipboard entered one at the end of every line.
We wanted to preserve the ones following periods, exclamation marks and the like.
We did not need double lines between paragraphs, as the text is displayed to the consumer through a Flash movie. It adds a space between paragraphs whether we want it or not.
Therefore, on every update or insert to the database I check, using the following code. It looks like a lot but is nearly instantaneous.
---- code starts --- // have to clean up the extraneous CR/LF combos $trupara = ".\r\n"; // period+CR+LF $dblquotpara = '"'."\r\n"; // double quote+CR+LF $sglquotpara = "'"."\r\n"; // single quote+CR+LF $questnpara = "?\r\n"; // question+CR+LF $exclampara = "!\r\n"; // exclamation+CR+LF $colonpara = ":\r\n"; // exclamation+CR+LF $dudspc = ". \r\n"; // period+spc+CR+LF $flspara = "\r\n"; //CR+LF $truflag = "***"; //something unique
$txtBody = str_replace ( $trupara, $truflag, $txtBody); $txtBody = str_replace ( $dblquotpara, "$$$", $txtBody); $txtBody = str_replace ( $sglquotpara, "%%%", $txtBody); $txtBody = str_replace ( $questnpara, "+++", $txtBody); $txtBody = str_replace ( $exclampara, "!!!", $txtBody); $txtBody = str_replace ( $colonpara, ":::", $txtBody); $txtBody = str_replace ( $dudspc, "###", $txtBody);
$txtBody = str_replace ( $flspara, " ", $txtBody);
$txtBody = str_replace ( $truflag, ".\n\n", $txtBody); ///double quote
$txtBody = str_replace ( "$$$", '"\n', $txtBody); ///single quote
$txtBody = str_replace ( "%%%", "'\n", $txtBody); ///question mark
$txtBody = str_replace ( "+++", '?\n', $txtBody); ///exclamation mark
$txtBody = str_replace ( "!!!", '!\n', $txtBody); ///colon
$txtBody = str_replace ( ":::", ':\n', $txtBody); ///dudspace
$txtBody = str_replace ( "###", '.\n\n', $txtBody);
$txtBody = str_replace ( "\n ", "\n", $txtBody);
--code ends ---
The final one cleans up the text so that there is no leading space on the following line.
If we need extra spaces, etc., then <br /> or <br> tags are used. (Flash is weird - if we wanted to split a headline in two we had to use the first form, the second caused output to choke. Auugh!)
When the story is called back for editing, stripslashes() is called against the text fields.
When the story is fed for display in the movie, the text is filtered using stripslashes, and nothing else.
When the story is fed for printing, the text body is processed this way, $stext = $row[ txtBody ] ; $stext = stripslashes( $row[ txtBody ] ); $stext = ereg_replace("(\r\n|\n|\r)", "<br />", $stext);
The last line was cribbed from the comments for the nl2br() section of the manual. $row[txtBody] is what's returned from the database.
Although it was only 3 wk ago, I know I played with nl2br() but it gave me more grief than I wanted, the above works for us.
Hope this helps - Miles Thompson
(Apologies to the ereg_replace() experts who would have done the above on one line.)
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php