Get content from another site with Curl and PHP

Posted: January 20, 2011 in PHP5
Tags:

<?php
function get_string_between($string, $start, $end)
{
$string = ” “.$string;
$ini = strpos($string,$start);
if ($ini == 0)
return “”;
$ini += strlen($start);
$len = strpos($string,$end,$ini) – $ini;
return substr($string,$ini,$len);
}
//Initialize the Curl session
$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the URL
curl_setopt($ch, CURLOPT_URL,”http://www.dsebd.org/&#8221;);
//Execute the fetch
$data = curl_exec($ch);

echo $da=get_string_between($data,’imgs/topdown.gif”>’,’imgs/topdown.gif’);
//Close the connection
curl_close($ch);

?>

Advertisements
Comments
  1. Excellent piece. I was checking continuously this blog and I am quite impressed! Very useful information specifically the last part. I care for such info a lot. I was looking for this particular info for a very long time. Thank you and best of luck.

  2. Excellent post. I was checking constantly this blog and I am quite impressed! Extremely useful info specifically the last part. I care for such info a lot. I was seeking this certain info for a long time. Thank you and good luck.

  3. Sid says:

    Nice work. Thanks for visiting my blog. I’ll visit your blog for CURL tweaks.

  4. xaos says:

    Awesome !!! hope you have some more updates soon … who really appreciate your help in similar aspects ! 🙂 cheers

  5. hoai says:

    Cool, thank amit

  6. prathz says:

    Excellent article.I love it.How can i fetch data from 2 or more websites at a time by passing parameters to query strings and show that data in my site.Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s