Re: [PHP] formatting paragraphs in to strings
Use the PHP str_replace function before writing it to the DB. Replace all \n characters with an empty string . http://us2.php.net/manual/en/function.str-replace.php On 6/13/05, Paul Nowosielski [EMAIL PROTECTED] wrote: Hi, I'm having a perplexing problem. I'm gather data through a textarea html from field and dumping it to MySQL. I want to display the data as a long string with no carriage returns or line breaks in a dhtml div window. The problem I'm have is that the form data is remembering the carriage returns. I tried using trim() and rtrim() with no luck. The data is still formatted exactly like it was inputed. Any ideas why this is happening and how I can format the text properly?? TIA! -- Paul Nowosielski Webmaster CelebrityAccess.com 303.440.0666 ext:219 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] formatting paragraphs in to strings
Use the PHP str_replace function before writing it to the DB. Replace all \n characters with an empty string . http://us2.php.net/manual/en/function.str-replace.php I think it might be better to replace all \n characters with spaces , otherwise you will end up with sentences that have no space break between them. Ie: original text This is the first sentence. This is the second sentence. /original text ...would become: replaced text This is the first sentence.This is the second sentence. /replaced text Regards, Murray -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] formatting paragraphs in to strings
Good point. Only problem is, if someone hit enter a-million times, you would end up with a-million spaces where the \n characters were. To take care of that repetition, maybe something like: while (strpos($textarea_text, \n\n)) { . } would be one way you could do it. On 6/13/05, Murray @ PlanetThoughtful [EMAIL PROTECTED] wrote: Use the PHP str_replace function before writing it to the DB. Replace all \n characters with an empty string . http://us2.php.net/manual/en/function.str-replace.php I think it might be better to replace all \n characters with spaces , otherwise you will end up with sentences that have no space break between them. Ie: original text This is the first sentence. This is the second sentence. /original text ...would become: replaced text This is the first sentence.This is the second sentence. /replaced text Regards, Murray -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] formatting paragraphs in to strings
Good point. Only problem is, if someone hit enter a-million times, you would end up with a-million spaces where the \n characters were. To take care of that repetition, maybe something like: while (strpos($textarea_text, \n\n)) { . } would be one way you could do it. Ordinarily most browsers render multiple consecutive spaces as a single space. This doesn't mean that it's not a good idea to remove them, just that not doing so shouldn't effect the way the text is displayed in the div tag, as the original poster mentioned was his intention. Regards, Murray -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] formatting paragraphs in to strings
Right.. But the browser also should be ignoring the carriage returns as well, which makes me think the div is set to white-space: pre; or something. He said the text is being formatted in a div exactly how it is entered into the system. By default, a div does not render any carriage returns. On 6/13/05, Murray @ PlanetThoughtful [EMAIL PROTECTED] wrote: Good point. Only problem is, if someone hit enter a-million times, you would end up with a-million spaces where the \n characters were. To take care of that repetition, maybe something like: while (strpos($textarea_text, \n\n)) { . } would be one way you could do it. Ordinarily most browsers render multiple consecutive spaces as a single space. This doesn't mean that it's not a good idea to remove them, just that not doing so shouldn't effect the way the text is displayed in the div tag, as the original poster mentioned was his intention. Regards, Murray -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] formatting paragraphs in to strings
On Mon, June 13, 2005 12:06 pm, Paul Nowosielski said: I'm having a perplexing problem. I'm gather data through a textarea html from field and dumping it to MySQL. I want to display the data as a long string with no carriage returns or line breaks in a dhtml div window. What styles have you applied to the div and surrounding elements? The problem I'm have is that the form data is remembering the carriage returns. I tried using trim() and rtrim() with no luck. The data is still formatted exactly like it was inputed. That sounds like PRE tag (or 'pre' style) or perhaps http://php.net/nl2br is being used when you don't really want that. Any ideas why this is happening and how I can format the text properly?? Show us actual output, like a URL for better guesses. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] formatting paragraphs in to strings
Good point. Only problem is, if someone hit enter a-million times, you would end up with a-million spaces where the \n characters were. To take care of that repetition, maybe something like: while (strpos($textarea_text, \n\n)) { . } would be one way you could do it. $new_str = ereg_replace([\n\r]+, , $textarea_text); would be another and avoid the loop as well at the expense of adding some regexps :) On 6/13/05, Murray @ PlanetThoughtful [EMAIL PROTECTED] wrote: Use the PHP str_replace function before writing it to the DB. Replace all \n characters with an empty string . http://us2.php.net/manual/en/function.str-replace.php I think it might be better to replace all \n characters with spaces , otherwise you will end up with sentences that have no space break between them. Ie: original text This is the first sentence. This is the second sentence. /original text ...would become: replaced text This is the first sentence.This is the second sentence. /replaced text Regards, Murray -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php