The ec (2); file_get_contents () function reads the entire file into a string. Like file (), the difference is that file_get_contents () reads the file into a string. The file_get_contents () function is the preferred method for reading the file content into a string. If supported by the operating system, the memory ing technology will be used to enhance the performance. Syntax file_get_contents (path, inclu script ec (2); script
The file_get_contents () function reads the entire file into a string.
Like file (), the difference is that file_get_contents () reads the file into a string.
The file_get_contents () function is the preferred method for reading the file content into a string. If supported by the operating system, the memory ing technology will be used to enhance the performance.
Syntax
File_get_contents (path, include_path, context, start, max_length) parameter description
Path is required. Specifies the file to be read.
Optional. If you want to search for files in include_path, you can set this parameter to "1 ".
Context is optional. Specifies the file handle environment.
Context is a set of options that can modify the behavior of a stream. If null is used, this parameter is ignored.
Start is optional. Specifies the location where the file starts reading. This parameter is newly added to php tutorial 5.1.
Max_length is optional. The number of bytes to read. This parameter is newly added in php 5.1.
Php code
Function post ($ url, $ post = null)
{
$ Context = array ();
If (is_array ($ post ))
{
Ksort ($ post );
$ Context ['http'] = array
(
'Method' => 'post ',
'Content' => http_build_query ($ post ,'','&'),
);
}
Return file_get_contents ($ url, false, stream_context_create ($ context ));
}
$ Data = array
(
'Name' => 'test ',
'Email '=> 'test @ gmail.com ',
'Submit '=> 'submit ',
);
Echo post ('HTTP: // localhost/5-5/request_post_result.php', $ data );
?>
Receive data:
Request_post_result.php receives post data:
Php code
Echo $ _ post ['name'];
Echo $ _ post ['email '];
Echo $ _ post ['submit '];
Echo "fdfd ";
?>
Instance 2
/**
* Other Versions
* Usage:
* $ Post_string = "app = request & version = beta ";
* Request_by_other ('HTTP: // facebook.cn/restserver.php', then post_string );
*/
Function request_by_other ($ remote_server, $ post_string ){
$ Context = array (
'Http' => array (
'Method' => 'post ',
'Header' => 'content-type: application/x-www-form-urlencoded'. "rn ".
'User-agent: jimmy's post example beta '. "rn ".
'Content-length: '. strlen ($ post_string) + 8,
'Content' => 'mypost = '. $ post_string)
);
$ Stream_context = stream_context_create ($ context );
$ Data = file_get_contents ($ remote_server, false, $ stream_context );
Return $ data;
}