1

I'm selecting a text column in a MySQL query for export to a csv file in a PHP script. It turns out the text column has carriage returns which is causing an issue with import on the other end.

How do I remove carriage returns while making the query and just present the text? Here is my current query:

SELECT marketing_remarks AS MarketingRemarks WHERE column = "blah"
8
  • Seems Google has the answer... google.co.uk/#q=php%20remove%20carriage%20return%20line%20feed - or is there a more specific problem you have? Commented Nov 7, 2013 at 11:52
  • The problem is not the select, the problem is that I need to remove the carriage returns in the result. Commented Nov 7, 2013 at 11:52
  • @ChrisW ...I don't see a SQL solution here, only PHP...I tried Google ;-) Commented Nov 7, 2013 at 11:54
  • Is there a reason you don't want to do it in PHP? Commented Nov 7, 2013 at 11:55
  • Yes, I want to keep it in a single MySQL statement for ease of administration. Cleaner code, I only want PHP where I absolutely have to (creation of the export file etc.). If it concerns data processing, I figure it is better to keep that within the SQL and PHP for file operations. Commented Nov 7, 2013 at 11:59

2 Answers 2

4
SELECT REPLACE(marketing_remarks, '\r', '') AS MarketingRemarks WHERE column = "blah"

Something like this?

Sign up to request clarification or add additional context in comments.

Comments

1

You can either do it in the query (as per Fredd's answer), or in the PHP:

str_replace("\r", '', $result); // remove carriage returns

there will be factors which will determine which is the best approach for you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.