Skip to content

Instantly share code, notes, and snippets.

@Anahkiasen
Last active October 31, 2024 15:00
Show Gist options
  • Save Anahkiasen/8803434 to your computer and use it in GitHub Desktop.
Save Anahkiasen/8803434 to your computer and use it in GitHub Desktop.
curl
<?php
/**
* Object-oriented wrapper for CURL
*/
class Curl
{
/**
* The internal CURL instance
*
* @var resource
*/
protected $curl;
/**
* Build a new Curl instance
*
* @param string $url
*/
public function __construct($url)
{
$this->curl = curl_init();
$this->url = $url;
}
/**
* Set a CURL option
*
* @param string $key
* @param mixed $value
*/
public function __set($key, $value)
{
$option = constant('CURLOPT_'.strtoupper($key));
curl_setopt($this->curl, $option, $value);
}
/**
* Send and get results
*
* @return mixed
*/
public function send()
{
$results = curl_exec($this->curl);
curl_close($this->curl);
return $results;
}
}
@Anahkiasen
Copy link
Author

<?php
$curl = new Curl('http://google.fr');
$curl->returnTransfer = true;

$results = $curl->send();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment