views:

82

answers:

4

So I'm writing a post on my wall and type a URL into the main body of the post. As soon as I finish the URL, Facebook creates a little section underneath which has the title, description, and an image from the url I typed.

Without getting too indepth, how is this done and what is the best way of make something similar myself?

A: 

I believe Facebook is written in PHP. And PHP does this easily.

FOpen can be used to access files on other sites. There are other functions but this will get you started. Then it's a matter of parsing the html you get from the url to get what you want.

http://php.net/manual/en/function.fopen.php

smdrager
Facebook uses a heavily modified version of PHP; however, php does do this easily.
Chris Lively
PHP, being server-side, would not be able to see what you had typed in a box without being submitted. It would have to be some combination of javascript, AJAX, and PHP. I also thought Facebook had moved off PHP, but I could be thinking of some other site.
tloach
@tloach: Facebook still uses the language, but they have their own processor which compiles it. See http://www.readwriteweb.com/archives/facebook_gets_faster_debuts_homegrown_php_compiler.php
Chris Lively
Yes I had heard it was heavily modified... it would have to be for their amount of traffic.And yes, jQuery would be needed to immediately parse user input (rather than on submit).
smdrager
+2  A: 

jQuery (or some other framework that lets you do Ajax easily) to communicate between browser client and webserver

PHP/ASP.NET/Python (or some other scripting framework on the backend) to fetch the url

Facebook also has a meta data specification you might be interested in, to let developers further define what gets shown in a Facebook page.

Dan Esparza
A: 

You have a couple choices. You can fetch it using Ajax from the client; or you can fetch it from your server.

If doing it from your server in asp.net then you need to use HttpWebRequest.

Chris Lively
A: 

FB does an asynchronous JavaScript call to fetch that data without reloading the window you're on. Lookup ajax and libraries like jquery do this: http://api.jquery.com/category/ajax/

M Sleman