Facebook like fetch url data using PHP Curl, Jquery and Ajax

Last modified on by Karthikeyan K

Hi guys ..

Here I am going to share how to fetch/extract url datas like title , description and images from a website like facebook attach url module

I have used PHP curl to fetch the webpage content as a string. And I have used PHP Domdocument object to extract the meta title and description part.

Finally I have used preg_match_all function to fetch images from the webpage

here is the code below

[php][file]http://w3lessons.info/wp-content/uploads/2012/01/facebook-like-fetch-url-data.txt[/file][/php]

Check out my latest facebook scripts

  1. Facebook Style Youtube Video Expander with JQuery – http://w3lessons.info/2013/05/08/facebook-style-youtube-video-expanding-with-jquery/
  2. Facebook Style Wall Script 3.0 – http://w3lessons.info/2013/04/21/facebook-wall-script-3-0-timeline-oauth-location-sharing-smileys-many-more/

View Demo Download

You May Also Like

38 Responses

  1. Hari and Vishnu says:

    thanks…..
    nice work…..

  2. Karthik says:

    it works very well on restricted hosting providers as well..good job
    thanks

  3. udhay says:

    Well done kartik…i have one doubt..currently i am working in .net,i need like this kind of extratcting url data other then PHP..can u help me to do? thanks in advance

  4. Sushin says:

    Can you help me in implementing this functionality using c#.net

  5. Sean says:

    Why is the demo not working?

    • Hi Sean,

      Now check it out. – http://w3lessons.info/demo/facebook-like-fetch-url-data/

      let me know If you any problem..

      Thanks
      Karthikeyan K

    • Atanas from Bulgaria says:

      when you trying to open the file

      if you getting the following:
      Fatal error: Call to undefined function: curl_init()

      It is maybe for one of these reasons

      If this is with a hosting company, you will need to have them install/enable it.

      If this is a Windows based system, CURL can be enabled by uncommenting the curl extension line in the php.ini file – extension=php_curl.dll and restarting the web server.

      If this is Unix/Linux, PHP must be compiled with CURL support and the libcurl library must be installed.

  6. Adel says:

    Hi !!
    It’s very nice … thank you for this
    But I have some problems in this app
    this function curl_init(); … it don’t want to engaging … I use appserv 2.5.8 for Windows

  7. Khaljava says:

    I downloaded example, but it doesn’t work at all.
    After submitting FireBug sad that:

    Node cannot be inserted at the specified point in the hierarchy

    b[0]&&b[0].ownerDocument||c);var h=[],…a:a+”px”)}}),a.jQuery=a.$=f})(window);

    jquery-1.6.1.min.js

    Maybe jQuery not fresh?

  8. Khaljava says:

    Thanks for so quick reply.
    I don’t understand that example can run only on server. After uplouding it to my localhost (Vertrigo Server) it started work. But with errors

    Notice: Undefined variable: description in
    VertrigoServwwwcurl_fetch.php on line 69 and on line 91

  9. Afsar says:

    Same problem on my localhost … its showing few errors same as Khaljava …
    I have enabled my localhost for curl … but still the script is not working

  10. iLen says:

    Hello, probe with the youtube link but the photos are not displayed

  11. Tibor says:

    Could you please check the ws. http://stipistop.com
    the images are not feched.

  12. swapnil says:

    i am getting the following fatal error plz help
    Call to undefined function curl_init()

  13. M Younis says:

    Thanks for the code but it didn’t work.. It’s giving the following error:
    Fatal error: Call to undefined function curl_init() in D:AppServwwwelandzfacebook-like-fetch-url-datacurl_fetch.php on line 20

  14. your well wisher says:

    i think you site is going vary good, so i suggest you please quick change you wordpress site into core php site its is hackable by any one

  15. Joe says:

    cheers dude this is helpful

  16. Flavio Lima says:

    Thanks for good script, clean and funcional!

  17. arosh says:

    how to insert tis data to a data base .please help

  18. DieFeM says:

    Thank you very much.

  19. Sachin Padha says:

    Hi Karthikeyan,

    If you post this URL on FB wall — http://www.justjammu.com/info then the information it is fetching incorrect title and description, whereas the above URL has Title and description and same URL is fetching correct information on your Demo Page (http://itzurkarthi.com/demo/facebook-like-fetch-url-data/)

  20. Toko Emas says:

    Does your website have a contact page? I’m having a tough time locating it but, I’d like
    to send you an e-mail. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it develop over time.

  21. Gaurav Kumar says:

    Its not working properly . In demo its working properly but when i download it and try to use , I give link in input field but its not fetching title , description and image also Please suggest .

    thank in advance

  22. sfantu says:

    Hi Karthikeyan K, it won’t working with other page like mp3 zing vn .Please help me. Thanks

  23. Sunkari Subbarayudu says:

    Notice: Undefined offset: 19 in C:xampphtdocsyohyohextractimageextractnewcurl_fetch.php on line 69

  24. Lawrence says:

    Great job for Facebook Wall Script 5.0

  25. Bayor says:

    i like this

    thanks you Karthikeyan K

  26. Siva Charan says:

    I am getting the following error in wamp “Fatal error: Call to a member function loadHTML() on a non-object “

  27. Dhvani Kotak says:

    Hi,

    this is really nice script, but it is not working with the sites having slideshows or ajax data.
    Can you tell me resolution for same?

    thanks.

  28. ComUP says:

    The demo currently didn’t work shows message ”

    Update Your Browser | Facebook
    ” .
    As I see it returns Title and description Only .
    I already have code that return only FaceBook upper and footer Div no page contents at all . I don’t know why but I think that data scrapped using Ajax o native Javascript codes .

  29. ComUP says:

    The demo currently didn’t work shows message ”

    Update Your Browser | Facebook
    ” .
    As I see it returns Title and description Only .
    I already have code that return only FaceBook upper and footer Div no page contents at all . I don’t know why but I think that data scrapped using Ajax o native Javascript codes .

Leave a Reply

Your email address will not be published. Required fields are marked *