Search code examples
phpcurlline-breaks

PHP - Linebreaks are missing after posting


I'm posting a message like the one below to Facebook via PHP cURL:

Hello world

This is a test

#hash

The entry on the Facebook wall is missing the linebreaks - the text looks like this:

Hello world This is a test #hash

This is my code:

$attachment =  array(
'access_token' => $token,
'message' => $postMessage
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$profileID.'/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
$result = curl_exec($ch);

How to make the linebreaks are send to?

P.S. Sorry for my english


Solution

  • Try to use nl2br function

    $attachment =  array(
    'access_token' => $token,
    'message' => nl2br($postMessage)
    );