7

It sounds like a pretty simple question but I can find the answer no where.

I have a post from a textarea. and I want to use the current facebook php library to do the following...

$description = $_POST['textarea_description'];

//magic happens

$attachment =  array(
'access_token' => $token,
'message' => "$title",
'picture' => "$image_url",
'link' => "$action_link",
'name' => "$action_label",
'caption' => "$caption",
'actions' => $action_json,
'description' => "$description",
 );

$facebook->api('/'.$my_uid.'/feed', 'POST', $attachment);

and have it work. Right now it seems to ignore

<br> <br /> \n \r \n\r \r\n

but I am sure I might have done something to screw up my testing.. I just need to replace 'magic happens' with something that works. Right now it just converts all of the newlines I am throwing at it to spaces.. Pretty frustrating. Someone on the facebook forums suggested addslashed() of all things... but that did not seem to work for me

Thanks, -FT

ShawnDaGeek
  • 4,145
  • 1
  • 22
  • 39
ftrotter
  • 3,066
  • 2
  • 38
  • 52
  • Check the facebook api to see if newlines are even supported in the description field. Chances are that they are stripping them out otherwise. – Fanis Hatzidakis Oct 13 '10 at 11:37
  • I would be surprised if it is possible, they are very strict to what is allowed in wall posts (nothing is allowed actually) – serg Oct 13 '10 at 15:48

2 Answers2

2

I write simple function which add &nbsp; after every row text.

public static function fbLinkDescriptionNewLines($string){
    $parts = explode("\n", $string);
    $row_limit = 60;

    $message = '';
    foreach($parts as $part){
      $str_len = strlen($part);
      $diff = ($row_limit - $str_len);

      $message .= $part;

      for($i=0; $i <= $diff; $i++){
        $message .= '&nbsp;';
      }
   }
    return $message;
}

NOTE: in your string you must use \n for new lines.

Faraona
  • 1,685
  • 2
  • 22
  • 33
2

If your lines of text are long enough, and you replace each space in each line with a non-breaking space ("&nbsp;") and put a regular space at the end of the line, then this will have the effect of forcing each line onto a new line, e.g.

This&nbsp;is&nbsp;some&nbsp;example&nbsp;text&nbsp;etc. This&nbsp;is&nbsp;some&nbsp;example&nbsp;text&nbsp;etc. This&nbsp;is&nbsp;some&nbsp;example&nbsp;text&nbsp;etc.

If any lines are too short, you can pad them out with &nbsp; chars

GStephens
  • 488
  • 4
  • 11