CURL alternative to fopen

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Momo

VIP Member
Impact
72
I'm installing a script which uses the fopen function, but my host Dreamhost has disabled this feature for security reasons. The suggested alternative was to use CURL, but I'm clueless as to what should I replace the code with.

Here is the part of the code which uses the said function:

Code:
$file = fopen($filename, "r");
        if (!$file) 
        {
            echo "<p>Unable to open remote file $filename.\n";
        }
        else
        {
            while (!feof($file))
            {
                $var = fgets($file, 1024);
                if(eregi("<font color=#008000>(.*)</font><nobr>",$var,$out))
                {
                    $out[1] = strtolower(strip_tags($out[1]));

$s1=str_replace("http://","",$out[1]);  
$ur1=str_replace("www.","",$s1);
$s=strpos($ur1," ");
if ($s > 3)$ur1=substr($ur1,0,$s);
$s=strpos($ur1,"/");
if ($s > 3)$ur1=substr($ur1,0,$s);
$ur1=str_replace("/","",$ur1);

                    $position++;
           
                   if($ur==$ur1)
                    {
                        $found = $position;          
                        break;
                    } 
                }
            }
        }
        fclose($file);    
    }

Could anybody guide me as to how to replace the fopen, fgets, etc functions with the CURL alternatives? Thanks a lot!
 
1
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Something like:
PHP:
$url = 'http://www.someurl.com/';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$var = curl_exec($ch);

if(eregi("<font color=#008000>(.*)</font><nobr>", $var, $out))
{
  $out[1] = strtolower(strip_tags($out[1]));
  $s1 = str_replace("http://", "", $out[1]);
  $ur1 = str_replace("www.", "", $s1);
  $s = strpos($ur1, " ");

  if($s > 3)
  {
    $ur1=substr($ur1, 0, $s);
  }
  $s = strpos($ur1, "/");

  if($s > 3)
  {
    $ur1 = substr($ur1, 0, $s);
  }
  $ur1 = str_replace("/", "", $ur1);
  $position++;

  if($ur == $ur1)
  {
    $found = $position;
    break;
  }
}
//Once done with everything...
curl_close($ch);
 
1
Close
Thank you SecondVersion, the code your posted worked well for me! :D Thanks again!
 
0
Close
No problem :)
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

A browser tab with a favicon next to the page title
Search members
You can now search for members by name, company, location and more. Open the search at the top of any page and choose Members. You will...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back