dongze8698 2014-10-09 00:34
浏览 19

为什么facebook不喜欢这段代码?

I've made some progress on getting facebook to share some adds grom my website that are generated dynamically from mysql database. I can insert an Iframe on the main page of my site.

<iframe src="//www.facebook.com/plugins/like.php? href=http://www.webaddress.com.au/description.php%3Fid%3D'.$id.'&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=80&amp;appId=596610807121620" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe>

Then on the page this links to I have the following metatags.

<meta property="og:title" content="Listed in the Two Year Olds section" />
  <meta property="og:url" content="<?php echo $_SERVER['PHP_SELF'];?>" />
  <meta property="og:description" content="<?php echo $row['horsename'];?> " />

Is there a more Facebook freindly way of doing this? As it seems to work sometimes but not all the time?

Thanks

  • 写回答

2条回答 默认 最新

  • duanba8070 2014-10-09 00:40
    关注

    First off, what makes you think Facebook doesn't like this code?

    Since you're saying it works sometimes and not others, I'm going to guess that the problem is that you're generating invalid HTML in some cases. Any time you use text in the context of HTML, you need to escape it. htmlspecialchars() can do this for you.

    <meta property="og:url" content="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" />
    <meta property="og:description" content="<?php echo htmlspecialchars($row['horsename']); ?> " />
    

    I might also suggest using a template engine, as this gets a little busy if you have a lot of dynamic content on your pages.

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退