首页 > 代码库 > file_get_contents高級用法

file_get_contents高級用法

Set_time_out(0);//防止脚本超时

function Post($url, $post = null){
        $context = array();
        if (is_array($post)) {
            ksort($post);

            $context[‘http‘] = array (
                ‘timeout‘=>60,
                ‘method‘ => ‘POST‘,
                ‘content‘ => http_build_query($post, ‘‘, ‘&‘),
             );
        }

        return file_get_contents($url, false, stream_context_create($context));
    }

    $data = http://www.mamicode.com/array (
        ‘name‘ => ‘test‘,
        ‘email‘ => ‘test@gmail.com‘,
        ‘submit‘ => ‘submit‘,
     );

     echo Post(‘http://www.example.com‘, $data);

file_get_contents高級用法