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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.