1

Facebook like button (XFBML) used this

<fb:like send="true" width="450" show_faces="true"></fb:like>
  1. Clearly the <fb></fb> is a tag, XML will accept it but it's not HTML. So is it normal that the browser keep it in the document?
  2. What kind of programming technique is this called? Is it the right way? Or just another way to create a hidden element and replace the id="fb" ?
  3. What is the :something in <fb:like> stands for? How to access it with javascript?
Thanh Trung
  • 3,566
  • 3
  • 31
  • 42

1 Answers1

0

This is XHP!

XHP is a PHP extension created by Facebook. It makes PHP understand XML nodes, so you can write something like this (from their own example):

<?php
  $href = 'http://www.facebook.com';
  echo <a href={$href}>Facebook</a>;
?>

XHP also allows you to create PHP classes, which can be used in your markup. So the <fb:like /> node is actually turned into a PHP class at compile time. The definition of the class probably looks like this:

<?php
  class :fb:like extends :x:element {
    ...
  }

You can read more about it in the link to Github above, and on the creators blog which is all about XHP.

So to answer your questions:

  1. will not be processed by the browser, but by XHP. XHP turns it into PHP objects, which lastly turns it into valid HTML tag(s). This is true when using XHP, but it is also possible for us to use the same tag, without XHP. I'm guessing this is just a matter of parsing the tag in javascript and sending the variable to the API, which probably uses API to recreate the structure, and send back the HTML.
  2. Not really a technique, but a unique thing that Facebook has developed to make their lifes working with PHP easier.
  3. Again, when it is returned to the browser, it has been transformed by XHP (after sending it to Facebook through javascript). Try looking at the rendered version - it looks different than the simple <fb:like> tag.
Frederik Wordenskjold
  • 10,031
  • 6
  • 38
  • 57
  • I thought FB api is javascript? – Thanh Trung May 22 '13 at 22:05
  • Facebook has a javascript library and a PHP library, which you can use (or both if you prefer). The Application Programming Interface (API) is just the external interface at Facebook that your reach when using their library. – Frederik Wordenskjold May 22 '13 at 22:09
  • 1
    It would still render in the browser, but it would not be valid HTML (5 at least). You can always access it in some way using javascript, but it would be a really unhandy way to do it. For example, you can't access it in jQuery using a normal selector: $('fb:like'); – Frederik Wordenskjold May 22 '13 at 22:18
  • @Leandro Villagran please don't be foolish and downvote my (perfectly valid) answers because you disagree with me in another thread. http://stackoverflow.com/questions/16701692/php-fetch-from-database-and-store-in-drop-down-menu-html/16701976#16701976 I'm trying to be fair here. – Frederik Wordenskjold May 22 '13 at 22:25