Jump to content

Changing from Fopen to Curl


CMNetworx

Recommended Posts

Hello, I am working on a host that does not allow fopen, which I have been able to work around for quite a few things, but here is one im getting hung up on..

 

The Fopen usage went like this

 

   function RockPaperScissors($URL)
      $this->URL = $URL;
      $this->initURL();

      $f = fopen($URL, "r");
      if($f)
         while($pre = fread($f, 1000))
            $this->source = $this->source.$pre;
      else
      {
         echo 'Unable to open '.$URL.'.';
         return false;
      }          
   }

 

Now, I am trying this in Curl, but Im doing something wrong, The Fopen outputs the information in a while statement $this->source = $this->source.$pre; How do I do this in curl? Here is how far I am..

 

   
function RockPaperScissors($URL)
   {
        $c = curl_init($URL);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        $f = curl_exec($c);
        curl_close($c);
      if($f)
return $f;
      else
      {
         echo 'Unable to open '.$URL.'.';
         return false;
      }          
   }

 

but I know thats not right, because the script is expecting it to return in $this>format

How do I do that?

 

Any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/40801-changing-from-fopen-to-curl/
Share on other sites

well, There is already a class in the script

 

class Info
{
   var $name = 'N/A';      // Name of the theater
   var $address = 'N/A';   // Address line one of the theater
   var $mapItURL = 'N/A';  // Map it URL, to display the yahoo map of the theater location
   var $infoURL = 'N/A';   // "Theater Info" link URL

 

I just don't know how to take the curl response and put it in there..

It looks like the fopen was just grabbing the first 1000 bytes?

Im guessing it would be something like this??

 

function RockPaperScissors($URL)
   {
        $c = curl_init($URL);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        $f = curl_exec($c);
        curl_close($c);
      if($f)
         while($pre = curl_exec($c, 1000))
            $this->source = $this->source.$pre;
      else
      {
         echo 'Unable to open '.$URL.'.';
         return false;
      }          
   }

 

Im not sure if that is right..

Anyone else dealt with this?

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.