duandan1995 2013-07-10 08:54
浏览 34
已采纳

php - Facebook上的帖子,包含双引号的消息

I am trying to post on Facebook wall, with following code. The message sometimes contains double quotes or other characters which is converted on wall, don't know how to get this resolved. Following is the code I am using

UPDATE

$title = get_the_title($post->ID); // using wordpress posts' title

//$title = "John's message has \"\" double quotes"; I thought it might be facebook doing something with the title. but by using raw according to Tim, it worked.

                    $attachment = array(
                        'access_token' => $smm_fb_access_token,
                        'message' => $title,
                        'name' => "Site.com",
                        'link' => $handler_url,
                    );

                    $facebook->api(sprintf('/%s/feed', $fb_id), 'POST', $attachment);

The post on Facebook becomes like that

John’s message has ““ double quotes.

Please guide what should I do to make it work?

  • 写回答

1条回答 默认 最新

  • doujujian0052 2013-07-10 08:59
    关注

    Nothing in your code would HTML-escape your $title string, so it's getting escaped elsewhere.

    The HTML encodings you've given are also 'fancy quotes' and not the ASCII characters in your example $title string. (i.e. not ") So if something else is escaping it, it's doing it quote deliberately. (like wordpress might cleverly do)

    I suggest posting more of your code that shows what's happening to the data on its journey to the Facebook SDK

    UPDATE

    As this is wordpress the $title string must be retrieved without HTML escaping. Avoid get_the_title which is escaped, and instead get the raw post title with

    $title = $post->post_title;
    // rest of your code.
    

    Note that Wordpress filters will NOT be applied to this string, which hopefully is what you want. If it is not what you want them you'll have to do as you were doing with get_the_title and then HTML decode the string. html_entity_decode won't help in your case because PHP can't decode the unicode entities. I strongly recommend the former approach regardless.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应