How to fetch / extract data using CURL in PHP?
- Sunday, February 13, 2011, 2:58
- How-to, PHP
- 16 comments
This is an example that fetches / extracts the information that we get while we search in google as define:words.
Open google.com and type define:zany in search box and press enter.
You will get list for definition of word zany.
In this example, using curl i am demonstrating to fetch the data from that page starting with <ul> tag to </ul> tag.
1 2 3 4 5 6 7 8 9 10 |
<?php $url = "http://www.google.com/search?q=define:zany"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $var= curl_exec($ch); curl_close($ch); $first= stripos($var,'<ul’,0) ; $second= stripos($var,'</ul>’,0) ; echo substr($var,$first,$second-$first); ?> |
About the Author
16 Comments on “How to fetch / extract data using CURL in PHP?”
Trackbacks
Write a Comment
Gravatars are small images that can show your personality. You can get your gravatar for free today!
Many thanks for providing this post. It is really essential for me.
I’m not easily ipmrsesed. . . but that’s impressing me! 🙂
Great article thanks
hi,
I need some help like i have api of one service provider and some tracking id’s. they are providing data in xml, and when i am passing id’s by using html text tag and posting to curl it is not coming but id is displaying on url. when i pass id directly it is comming. what to do.
Hello chand , thanks for your queries. Please recheck your codes or test by making similar example in your local host. Without seeing actual scenario i cannot help…
how to current status from this following file
http://trackntrace.aflwiz.com/aflwizhtmltrack?shpntnum=84252622306407166
Hello Chand, the code below will give you value of first Current Status found on page http://trackntrace.aflwiz.com/aflwizhtmltrack?shpntnum=84252622306407166 . Hope this helps.
< ?php $url = "http://trackntrace.aflwiz.com/aflwizhtmltrack?shpntnum=84252622306407166"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $var= curl_exec($ch); curl_close($ch); $first= stripos($var,'Current Status',0) ; $second= stripos($var,'</b>',$first) ; $start= stripos($var,'<b>',$first) ; echo substr($var,$start,$second-$start); ?>
2011-08-24 16:12
how to take only date from this in php
Hello friend chand, Please send your question clearly in my email mast.ratna@gmai.com so that i can find exact solution and help you. Thanks
Thanks a lot for your help.
How to fetch data in php(curl) from this site http://www.metrorailindia.com 1> i want train fare from one station to another 2> timings of train in current station 3> stations comes between one station to another
Good article and informative… keep it rock
i want to extract and display data(textual and binary data) from a website that provides informations about different cars falling under a specified range of price….can you help me?
i just want to use these urls in my database and search for the required data by crawling through these websites.
thank u .it helps me alot
Thanks a lot, much needed info. keep it up.