>  기사  >  php教程  >  PHP file_get_contents 简单函数

PHP file_get_contents 简单函数

WBOY
WBOY원래의
2016-08-04 08:53:381421검색
跳至 [1] [全屏预览]
/**
 * file_get_contents 函数
 * @param string $url @要访问的URL
 * @param array $post_data @请求的数据(数组)
 * @param string $method @请求方式 默认 post
 * @return bool|string
 */
function file_contents_post($url = '', $post_data = array(), $method = 'POST')
{
	$sFile = false;
	if(!empty($post_data) && !empty($url)){
		$data = http_build_query($post_data);
		$opts = array(
			'http'=>array(
				'method' => $method,
				'header' => "Content-type: application/x-www-form-urlencoded\r\n".
					"Content-length: ".strlen($data)."\r\n" .
					"Cookie: foo=bar\r\n" .
					"\r\n",
				'content' => $data
			)
		);
		$cxContext = stream_context_create($opts);
		$sFile = file_get_contents($url, false, $cxContext);
	}

	return $sFile;
}
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.