csv file - field contents appear on multiple lines

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vcarter
Forum Newbie
Posts: 14
Joined: Sun Jun 21, 2009 3:02 pm

csv file - field contents appear on multiple lines

Post by vcarter »

I'm trying to build a csv file from a database (and other static information) using php -- one of the fields, however, contains html -- this was intended.

When I load this field into the csv file, it returns the results on multiple lines. ie:

Instead of this:

<li>Item one</li><li>Item two</li>

It does this:

<li>Item one</li>
<li>Item two</li>

And, the purpose of the csv file is to use as an imported file for a specific program, but it doesn't work if the field's contents are on multiple lines.

How can I get it to all be on one line? I've tried replacing "\n" with a space, but that doesn't work.

TIA.
vcarter
Forum Newbie
Posts: 14
Joined: Sun Jun 21, 2009 3:02 pm

Re: csv file - field contents appear on multiple lines

Post by vcarter »

Just for clarification -- this is not a question about the csv file -- my question pertains to a php command I can use that will remove whatever is causing the text in that field to appear on multiple lines instead of in one single line.

Thanks :)
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: csv file - field contents appear on multiple lines

Post by McInfo »

Try replacing \r\n with a space.

Or, with preg_replace(), replace characters matched by \v (any vertical whitespace character).
vcarter
Forum Newbie
Posts: 14
Joined: Sun Jun 21, 2009 3:02 pm

Re: csv file - field contents appear on multiple lines

Post by vcarter »

THANK YOU!

Replacing \r\n did it.
Post Reply