Contain new line in field when exporting CSV file in php


hi,

It is really strange problem. There is a new line in my address field and when i am adding that value to download in CSV file , all column messed up.

I tried to use nl2br , str_replace , encoding function to find out solution of that mess. But nothing work.

Then I talk with one GURU (Boss 🙂 ) , he told me you need to use ” in place of  ‘  because PHP cant replace new line if it is quoted by single ‘.

I was just surprised,  then i used the function

str_replace(array(“\r\n”, “\n\r”,”\n”,”\r”),” “,$string);

It just work in one sec 🙂

So, I want to share this information to all my PHP developers because many of them might not know so as I . 🙂

 

 

Advertisements
  1. Leave a comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: