Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 51605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:46:36+00:00 2026-05-10T16:46:36+00:00

I have noticed that cURL in PHP returns different data when told to output

  • 0

I have noticed that cURL in PHP returns different data when told to output to a file via CURLOPT_FILE as it does when told to send the output to a string via CURLOPT_RETURNTRANSFER.

_RETURNTRANSFER seems to strip newlines and extra white space as if parsing it for display as standard HTML code. _FILE on the other hand preserves the file exactly as it was intended.

I have read through the documentation on php.net but haven’t found anything that seems to solve my problem. Ideally, I would like to have _RETURNTRANSFER return the exact contents so I could eliminate an intermediate file, but I don’t see any way of making this possible.

Here is the code I am using. The data in question is a CSV file with \r\n line endings.

function update_roster() {   $url         = 'http://example.com/';     $userID      = 'xx';     $apikey      = 'xxx';     $passfields  = 'userID=$userID&apikey=$apikey';    $file = fopen('roster.csv','w+');    $ch = curl_init();     curl_setopt($ch, CURLOPT_POST, 1);     curl_setopt($ch, CURLOPT_URL,$url);     curl_setopt($ch, CURLOPT_POSTFIELDS, $passfields);     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   curl_setopt($ch, CURLOPT_FILE, $file);   $variable_in_question = curl_exec  ($ch);     curl_close ($ch);    fclose($file);   return $variable_in_question;   } 

Turns out, the error is not in what was being returned, but in the way I was going about parsing it. \r\n is not parsed the way I expected when put in single quotes, switching to double quotes solved my problem. I was not aware that this made a difference inside function calls like that.

This works just fine:$cresult = split('\r\n', $cresult);

This does not: $cresult = split('\r\n', $cresult);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:46:36+00:00Added an answer on May 10, 2026 at 4:46 pm

    Turns out, the error is not in what was being returned, but in the way I was going about parsing it. \r\n is not parsed the way I expected when put in single quotes, switching to double quotes solved my problem. I was not aware that this made a difference inside function calls like that.

    This works just fine:$cresult = split('\r\n', $cresult);

    This does not: $cresult = split('\r\n', $cresult);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It gets constructed and deconstructed every iteration. However, on the… May 12, 2026 at 12:48 am
  • Editorial Team
    Editorial Team added an answer The signature of that method states that it returns a… May 12, 2026 at 12:48 am
  • Editorial Team
    Editorial Team added an answer Your problem is that your decode_escaped does not exactly undo… May 12, 2026 at 12:48 am

Related Questions

I'm using cURL and php to query an exchange server that has Forms Based
I have simple code that does a head request for a URL and then
I have noticed that some apps like Safari and Mail show a loading indicator
I have noticed that regardless of a given script's execution time, every date() call

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.