PHPHtmlParser\Curl::get PHP Method

get() public method

A simple curl implementation to get the content of the url.
public get ( string $url ) : string
$url string
return string
    public function get($url)
    {
        $ch = curl_init($url);
        if (!ini_get('open_basedir')) {
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        $content = curl_exec($ch);
        if ($content === false) {
            // there was a problem
            $error = curl_error($ch);
            throw new CurlException('Error retrieving "' . $url . '" (' . $error . ')');
        }
        return $content;
    }

Usage Example

 /**
  * Use a curl interface implementation to attempt to load
  * the content from a url.
  *
  * @param string $url
  * @param array $option
  * @param CurlInterface $curl
  * @chainable
  */
 public function loadFromUrl($url, $options = [], CurlInterface $curl = null)
 {
     if (is_null($curl)) {
         // use the default curl interface
         $curl = new Curl();
     }
     $content = $curl->get($url);
     return $this->loadStr($content, $options);
 }
Curl