private function _loadUrl($source, $charset = "", $mimetype = "")
    {
        $loadHeaders = (strlen($mimetype) == 0) || (strlen($charset) == 0);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $source);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, $loadHeaders);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
        $result = curl_exec($ch);
        curl_close($ch);

        // loads mime-type and charse
        if ($loadHeaders) {
            $headers = null;
            $separator = "\r\n\r\n";
            $pos = strpos($result, $separator);
            if ($pos !== false) {
                $headers = substr($result, 0, $pos);
                $content = substr($result, $pos + strlen($separator));
            }

            $lines = explode("\r\n", $headers);
            foreach ($lines as $line) {
                $regexp = '@Content-Type:\s*([\w/+]+)(;\s*charset=(\S+))?@i';
                if (preg_match($regexp, $line, $matches) > 0) {
                    if (strlen($mimetype) == 0) {
                        $mimetype = Arr::exist($matches, 1)
                            ? $matches[1]
                            : null;
                    }
                    if (strlen($charset) == 0) {
                        $charset = Arr::exist($matches, 3)
                            ? $matches[3]
                            : null;
                    }
                }
            }
        } else {
            $content = $result;
        }

        return array($content, $mimetype, $charset);
    }
private function _loadUrl($source, $charset = "", $mimetype = "")
    {
        $loadHeaders = (strlen($mimetype) == 0) || (strlen($charset) == 0);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $source);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, $loadHeaders);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
        $result = curl_exec($ch);
        curl_close($ch);

        // loads mime-type and charse
        if ($loadHeaders) {
            $headers = null;
            $separator = "\r\n\r\n";
            $pos = strpos($result, $separator);
            if ($pos !== false) {
                $headers = substr($result, 0, $pos);
                $content = substr($result, $pos + strlen($separator));
            }

            $lines = explode("\r\n", $headers);
            foreach ($lines as $line) {
                $regexp = '@Content-Type:\s*([\w/+]+)(;\s*charset=(\S+))?@i';
                if (preg_match($regexp, $line, $matches) > 0) {
                    if (strlen($mimetype) == 0) {
                        $mimetype = Arr::exist($matches, 1)
                            ? $matches[1]
                            : null;
                    }
                    if (strlen($charset) == 0) {
                        $charset = Arr::exist($matches, 3)
                            ? $matches[3]
                            : null;
                    }
                }
            }
        } else {
            $content = $result;
        }

        return array($content, $mimetype, $charset);
    }
private function _loadUrl ( $ source , $ charset = "" , $ mimetype = "" ) { $ loadHeaders = ( strlen ( $ mimetype ) == 0 ) || ( strlen ( $ charset ) == 0 ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ source ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_HEADER , $ loadHeaders ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , 120 ) ; $ result = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; // loads mime-type and charse if ( $ loadHeaders ) { $ headers = null ; $ separator = "\r\n\r\n" ; $ pos = strpos ( $ result , $ separator ) ; if ( $ pos !== false ) { $ headers = substr ( $ result , 0 , $ pos ) ; $ content = substr ( $ result , $ pos + strlen ( $ separator ) ) ; } $ lines = explode ( "\r\n" , $ headers ) ; foreach ( $ lines as $ line ) { $ regexp = '@Content-Type:\s*([\w/+]+)(;\s*charset=(\S+))?@i' ; if ( preg_match ( $ regexp , $ line , $ matches ) > 0 ) { if ( strlen ( $ mimetype ) == 0 ) { $ mimetype = Arr :: exist ( $ matches , 1 ) ? $ matches [ 1 ] : null ; } if ( strlen ( $ charset ) == 0 ) { $ charset = Arr :: exist ( $ matches , 3 ) ? $ matches [ 3 ] : null ; } } } } else { $ content = $ result ; } return array ( $ content , $ mimetype , $ charset ) ; }
Loads url contents.

<p>Loads the contents of a URL and, optionally, the mimetype and the
charset of the page.</p>

@param string $source   A filename or a URL
@param string $charset  Charset, autodetected (default is "")
@param string $mimetype Mime-type, autodetected (default is "")

@return array
Loads url contents .