Jump to content

Curl to get the contents of a remote web page into a PHP variable


dilbertone

Recommended Posts

 

Hi dear community

 

i want to run a Curl  to get the contents of a remote web page into a PHP variable

 

 

 

<?php
//
// The PHP curl module supports the received page to be returned in a variable
// if told.
//
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.myurl.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
?>

I declare this variable:($ch)

 

Well - can i work with this variable - eg. to parse this with a parser!?

 

look forward to hear from you

 

$result=curl_exec ($ch);

 

gretings

 

Hi dear friends,

 

i want to run a Curl  to get the contents of a remote web page into a PHP variable

 

 

 

and btw: if i add this code - i will clean the stuff from header and bottom content..!? Does  this work!?

 

 

<?php
//
// The PHP curl module supports the received page to be returned in a variable
// if told.
//
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.myurl.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
?>

I declare this variable:($ch)

 

Well - can i work with this variable - eg. to parse this with a parser!?

 

look forward to hear from you

 

$result=curl_exec ($ch);

 

greetings yours

meta


if($ch) {
// This will clean all the unneeded top and bottom content and return only
the table and divs data

$cleaned = string_between('onload="check();">', '</body>', $data);

// From here it's easy, clean out any unneeded content such as images and
divs
// Setting the second parameter, allows us to specify which tags NOT to
remove, ie. tables, divs, paragraphs etc.
// If we don't want any html tags, simply leave it as
strip_tags($cleaned);
// This will remove ALL the html tags and return only the content between.
return  = stip_tags($cleaned, '<table><tr><td><div>');
}

 

look forward to hear from you!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.