You are here: Re: Error creating CSV out of SQLdb « All PHP « IT news, forums, messages
Re: Error creating CSV out of SQLdb

Posted by Tyrone Slothrop on 12/07/05 17:08

On Wed, 7 Dec 2005 13:31:28 +0100, "ND" <daantje_l@hotmail.com> wrote:

>Hi,
>I have the following coding problem:
>
>I have a evaluation form with some questions.
>Some of these questions are answered by a textarea (which gives the user the
>possibillity to use [enter] and make a new line feed in the answer).
>The answers are recorded into a database.
>
>This all works fine, but!
>
>When I want to output my answers to a .csv file, the 'new line feeds' of the
>textarea fields are messing up my grid in the csv (excel text file seperated
>by semicolon ';').
>I write the answers to a file which can be downloaded but the 'new line'
>makes an abrupt stop to a line.
>
>Hope somebody understands the problem.
>How can I work around this 'little' error?
>
>I've tried the following without any results :-(
>
>$value=ereg_replace('\r\n','',$value);
>$value=ereg_replace('\r','',$value);
>$value=ereg_replace('\n','',$value);
>
>I'm guessing that since there is no actual \n to be found in the $value
>field it does not replace anything.
>
>the nl2br function DOES however recognize the \n but it keeps the \n in the
>text:
> a combination where \n is replaced by <br /> which is deleted in step2:
>
>$value=nl2br($value);
>$value=ereg_replace('<br />','',$value);
>
>But I still get the 'new lines' in my output file. I don't want this!! I
>want one continued file with info....
>
>
>Thanks a million!
>
>Daniel

I am not very good at regular expressions, but I am guessing that
ereg_replace is not interpreting your \n and \r's. Try usng
str_replace instead. Also str_replace supports arrays, so you can do
this:

$search = array("\r","\n");
$replace = array("","");
str_replace($search, $replace, $value);

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация