码迷,mamicode.com
首页 > 其他好文 > 详细

file_get_contents抓取远程URL内容

时间:2014-09-09 15:02:58      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   ar   for   div   

/**
     * POST URL
     * @param $url
     * @param null $post
     * @return false / string
     */
    public static function UrlPost($url, $post = null, $timeout = 3) {
        if (is_array($post)) {
            ksort($post);
            $content = http_build_query($post);
            $content_length = strlen($content);
            $options = array(
                ‘http‘ => array(
                    ‘method‘ => ‘POST‘,
                    ‘timeout‘ => ($timeout ? $timeout : 3),
                    ‘header‘ =>
                        "Content-Type: application/x-www-form-urlencoded\r\n" .
                        "Content-Length: $content_length\r\n",
                    ‘content‘ => $content
                )
            );
            return file_get_contents($url, false, stream_context_create($options));
        }
        return false;
    }

file_get_contents抓取远程URL内容代码示例

 

file_get_contents抓取远程URL内容

标签:style   blog   http   color   os   io   ar   for   div   

原文地址:http://www.cnblogs.com/imbin/p/3962213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!