19

I'm writing a simple Facebook status update web app that uses Graph API. It works well except for when I'd like to include a line break in the status message. I've tried adding a simple HTML
tag, but this is just rendered as text.

Anyone know if this is possible, and if so, how?

Crowie
  • 3,220
  • 7
  • 28
  • 48
Dan
  • 5,836
  • 22
  • 86
  • 140

17 Answers17

26

It sounds silly, but this works: Insert <center></center> where you would normally put <br>.

pmr
  • 58,701
  • 10
  • 113
  • 156
heksemann
  • 436
  • 4
  • 3
12

\r\n seems to work just fine to get line breaks in facebook

user566245
  • 4,011
  • 1
  • 30
  • 36
9

If you're using PHP or any language just add chr(10) and this will add a break :) ASCII Solution :P

8

Please observe the new line that is used in the below code (an enter is hit inside the editor), that serves the purpose of adding new line to a post at a specific location:

    $fb_status_with_new_line = "Text before new line" . "
    " . "Text after new line";
MotsManish
  • 485
  • 1
  • 8
  • 16
7

If you replace return characters (\r) with new line characters (\n) you can achieve the desired result.

Enjoy...

pmr
  • 58,701
  • 10
  • 113
  • 156
Mark Smerdon
  • 81
  • 1
  • 1
5

%0A might work, i think i used that on one of my apps before.

HTML Decimal: &#10;
HTML Hexadecimal: &#x0A;
Java Hexadecimal: \u000A (Common To Javascript)
URL Hexadecimal: %0A
Escape Sequence: \n

HTML tag : <br>

Hope these come in handy :)

DanCarlyon
  • 191
  • 3
  • 7
4

As of Dec 2013, this works (break lines in code):

$facebook->api('/me/feed', 'post', array('message'=> 'Line 1
                                             Line 2
                                             Line 3
                                             Line 4',
                                             'cb' => ''));
Roger Gajraj
  • 523
  • 4
  • 12
4

I've tried <center></center> it didn't work. I've tried <br> it didn't work. I've tried with invisible html characters, it didn't work. I've tried with '\n' it didn't work.

However when I used "\n" instead of '\n' it worked. But this was recognized directly by the php before it was uploaded to facebook. So my suggestion is using double quotes with string messages in facebook posts.

David
  • 49
  • 1
  • 1
  • 1
    Oddly enough, this is the only answer that worked for me as of June 2015 – ctown4life Jun 03 '15 at 00:28
  • I use the messenger API, and this is the reverse : the only thing that works is putting the 2-char string '\n', and not the newline char "\n". – ofaurax Sep 01 '16 at 13:49
2

If you are using PHP, you can do like this:

$message = str_replace('\r\n', "\n", $message); // input is from textarea
$ret_obj = $facebook->api('/me/photos', 'POST', array(
                                             'source' => '@' . $photo['file_source'],
                                             'message' => $message)
                                            );

Please use double quote "\n" instead '\n'

rusly
  • 1,504
  • 6
  • 28
  • 62
1

\n Worked Its smallest an easiest way to add line breaks

Kumar Pallav
  • 590
  • 1
  • 6
  • 16
1

You need to add carriage return i.e \n\r because facebook accept only enter for new line.

Mahesh
  • 2,862
  • 2
  • 31
  • 41
1

\n works. You just need to add it to the message param

Alex M
  • 31
  • 3
1

\n working I checked now on twitter. $post = $connection->post('statuses/update', array('status' => "first line \n second line")); Just do it like so, It will work for other social media also

Aammad Ullah
  • 274
  • 4
  • 11
1

I use the messenger API with PHP. For me, the string '\n' is working. Beware that this is not the newline character (aka "\n"). No, it's '\' followed by 'n', aka "plain antislash-N".

ofaurax
  • 1,417
  • 1
  • 20
  • 27
0

if You are using iOS mobile platform the \n will supports fine.. message = encodeURIComponent(message) .. bur for android nothing is working for me searching for me..

Sandeep P
  • 4,291
  • 2
  • 26
  • 45
0

None of the solutions offered worked for me when trying to post a comment on Facebook using Chrome. The only solution I have found is to highlight text that has a linefeed, then paste in that text, then erase all of the paste except the linefeed.

Robert
  • 1
0

In my case (in bash) newline works only with newline character $'\n', e.g.

echo "Message text"$'\n'"#kw"
Pavel
  • 182
  • 1
  • 9