예제 #1
0
 /**
  * Load page with url
  */
 function load($url, $p = array())
 {
     $close = false;
     if (!isset($p["_"]) || $p["_"] == null) {
         $close = true;
         $p["_"] = curl_init();
     }
     xurl::_setopts($p["_"], $p);
     // Use limit
     if (isset($p["limit"]) && $p["limit"] > 0) {
         curl_setopt($p["_"], CURLOPT_RETURNTRANSFER, 0);
         curl_setopt($p["_"], CURLOPT_BUFFERSIZE, $p["limit"]);
         $cwriter = isset($p["writer"]) && $p["writer"] !== "" ? "urlwriter" : $p["writer"];
         curl_setopt($p["_"], CURLOPT_WRITEFUNCTION, array($w = new $cwriter($p["limit"]), "write"));
     }
     curl_setopt($p["_"], CURLOPT_URL, $url);
     $res = curl_exec($p["_"]);
     // Use limit
     if (isset($p["limit"]) && $p["limit"] > 0 && curl_getinfo($p["_"], CURLINFO_HTTP_CODE) != 404) {
         $res = $w->content;
     } else {
         if (curl_errno($p["_"]) || curl_getinfo($p["_"], CURLINFO_HTTP_CODE) == 404) {
             $res = "";
             trigger_error("CURL Error: " . curl_errno($p["_"]) . " - " . curl_error($p["_"]), E_USER_WARNING);
         } else {
             if (isset($p["result"]) && $p["result"] && strlen($res) == 0) {
                 trigger_error("CURL Error: " . curl_errno($p["_"]) . " - " . curl_error($p["_"]), E_USER_WARNING);
             }
         }
     }
     if (isset($p["getinfo"]) && $p["getinfo"] === true && $res !== "") {
         $info = curl_getinfo($p["_"]);
     }
     if ($close) {
         curl_close($p["_"]);
         $p["_"] = null;
     }
     if (isset($p["getheaders"]) && $p["getheaders"] === true && $res !== "") {
         return xurl::extractheaders($res);
     }
     if (isset($p["getinfo"]) && $p["getinfo"] === true && $res !== "") {
         return array($info, $res);
     }
     return $res;
 }