Home > php教程 > PHP源码 > body text

PHP file_get_contents simple function

WBOY
Release: 2016-08-04 08:53:38
Original
1429 people have browsed it
跳至 [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;
}
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!