问题描述
这听起来像一个很简单的问题,但是我可以找到没有哪里的答案。我有一个textarea的帖子。我想使用当前的Facebook php库来执行以下操作...
$ description = $ _POST ['textarea_description' ]。
//魔术发生
$ attachment = array(
'access_token'=> $ token,
'message'=>$标题,
'picture'=>$ image_url,
'link'=>$ action_link,
'name'=>$ action_label,
'caption'=>$ caption,
'actions'=> $ action_json,
'description'=>$ description,
);
$ facebook-> api('/'.$ my_uid。'/ feed','POST',$ attachment);
并让它工作。现在似乎忽略了
< br> < br /> \\\
\r \\\
\r \r\\\
但我是确定我可能已经做了一些事来扭转我的测试..我只需要替换'魔术发生'与某些工作。现在它只是将所有的换行符转换成空格。令人沮丧的是。 Facebook的论坛上的人建议添加所有的东西...但似乎没有为我工作
谢谢
-FT
我写了简单的功能,在每行行文本后添加& nbsp;
public static function fbLinkDescriptionNewLines($ string){
$ parts = explode(\\\
,$ string );
$ row_limit = 60;
$ message ='';
foreach($ parts as $ part){
$ str_len = strlen($ part);
$ diff =($ row_limit - $ str_len);
$ message。= $ part; ($ i = 0; $ i $ = $ diff; $ i ++)
{
$ message。='& nbsp;';
}
}
return $ message;
}
注意:在字符串中,您必须使用 \ n
为新行。
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
I write simple function which add
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 .= ' ';
}
}
return $message;
}
NOTE: in your string you must use \n
for new lines.
这篇关于如何添加换行符或回车到facebook图形API的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!