cURL / Mailing Lists / curl-users / Single Mail

curl-users

Newlines being lost during curl transmission

From: Matthew Hellinger <curl_at_webspacecreations.com>
Date: Fri, 24 Oct 2003 01:16:41 -0500

Hi all,

I am having an unexpected problem with a PHP script that I wrote. The script
uses curl to post to a textarea. It works fine, except for when the message
being posted contains a newline character. What happens is that the newline
character appears to be lost when the form is submitted. The form does not
normally strip newline characters (when accessing it using a web browser),
so I've ruled this possibility out. I've tried using \r , \r\n , and \n to
specify a newline in the textarea element, but all variants appear to get
stripped.

I'm including sample code. I've tested to verify that the $message is
printing the newline and that the 'field2' element of the $submit array
contains the newline character. Am I missing something in the curl
initialization protocol? What else could be the problem be, except for one
of the curl function calls?

Thank you very much for your help. I've been searching for several days and
not finding a satisfactory answer
Matthew Hellinger

// A variable contain newline characters
$message = "Line 1\r\nLine2";

// Next, build array to post
$submit = array("field1" => 'exampletext',
"field2" => $message);

// Now we initialize curl
$ch = curl_init("mydomain.com");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $submit);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Now, initiate transfer
$data = curl_exec($ch);

-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community? Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
Received on 2003-10-24