use_include_path
-------------------------------------------------- --------------------------------
As of PHP 5, you can use the constant FILE_USE_INCLUDE_PATH to locate the file in the include path.
context
Correct resource context created using the stream_context_create (). If you use a special context is not necessary, you can skip this parameter passing in the value is NULL.
---------------------------------------------------------------------------------------------------------
offset
The offset from which to start reading the original thread.
Search bias (offset) is not supported when working with remote files. Attempting to find bias nonlocal files may operate with small displacements, but this result is unexpected, since it operates on buffered stream.
--------------------------------------------------------------------------------------------------------------
maxlen
The maximum size of the data being read. By default, reading is performed until the end of the file. Note that this setting applies to the flow filters.
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
Get and display the source code of the web site home page
<?php
$homepage = file_get_contents('http://www.google.com/');
echo $homepage;
?>
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
Search files in the include_path
<?php
// <= PHP 5
$file = file_get_contents('./people.txt', true);
// > PHP 5
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
?>
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
Reading section of the file
<?php
// Read 14 characters, starting with 21 characters
$section = file_get_contents('./people.txt', NULL, NULL, 20, 14);
var_dump($section);
?>
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
Using streaming contexts
<?php
// create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
// Open the file using a set up HTTP-headers
$file = file_get_contents('http://www.google.com/', false, $context);
?>
----------------------------------------------------------------------------------------------------------------------------------------------
My Setting timeout
<?php
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 1
)
)
);
file_get_contents("http://google.com/", 0, $ctx);
---------------------------------------------------------------------------------------------------------------------------------------------
I decided to make a similar function to this, called file_put_contents, it uses POST to call, handy...
<?php
function file_post_contents($url,$headers=false) {
$url = parse_url($url);
if (!isset($url['port'])) {
if ($url['scheme'] == 'http') { $url['port']=80; }
elseif ($url['scheme'] == 'https') { $url['port']=443; }
}
$url['query']=isset($url['query'])?$url['query']:'';
$url['protocol']=$url['scheme'].'://';
$eol="\r\n";
$headers = "POST ".$url['protocol'].$url['host'].$url['path']." HTTP/1.0".$eol.
"Host: ".$url['host'].$eol.
"Referer: ".$url['protocol'].$url['host'].$url['path'].$eol.
"Content-Type: application/x-www-form-urlencoded".$eol.
"Content-Length: ".strlen($url['query']).$eol.
$eol.$url['query'];
$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
if($fp) {
fputs($fp, $headers);
$result = '';
while(!feof($fp)) { $result .= fgets($fp, 128); }
fclose($fp);
if (!$headers) {
//removes headers
$pattern="/^.*\r\n\r\n/s";
$result=preg_replace($pattern,'',$result);
}
return $result;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
Thank,goodbye :a5:
-------------------------------------------------- --------------------------------
As of PHP 5, you can use the constant FILE_USE_INCLUDE_PATH to locate the file in the include path.
context
Correct resource context created using the stream_context_create (). If you use a special context is not necessary, you can skip this parameter passing in the value is NULL.
---------------------------------------------------------------------------------------------------------
offset
The offset from which to start reading the original thread.
Search bias (offset) is not supported when working with remote files. Attempting to find bias nonlocal files may operate with small displacements, but this result is unexpected, since it operates on buffered stream.
--------------------------------------------------------------------------------------------------------------
maxlen
The maximum size of the data being read. By default, reading is performed until the end of the file. Note that this setting applies to the flow filters.
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
Get and display the source code of the web site home page
<?php
$homepage = file_get_contents('http://www.google.com/');
echo $homepage;
?>
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
Search files in the include_path
<?php
// <= PHP 5
$file = file_get_contents('./people.txt', true);
// > PHP 5
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
?>
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
Reading section of the file
<?php
// Read 14 characters, starting with 21 characters
$section = file_get_contents('./people.txt', NULL, NULL, 20, 14);
var_dump($section);
?>
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
Using streaming contexts
<?php
// create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
// Open the file using a set up HTTP-headers
$file = file_get_contents('http://www.google.com/', false, $context);
?>
----------------------------------------------------------------------------------------------------------------------------------------------
My Setting timeout
<?php
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 1
)
)
);
file_get_contents("http://google.com/", 0, $ctx);
---------------------------------------------------------------------------------------------------------------------------------------------
I decided to make a similar function to this, called file_put_contents, it uses POST to call, handy...
<?php
function file_post_contents($url,$headers=false) {
$url = parse_url($url);
if (!isset($url['port'])) {
if ($url['scheme'] == 'http') { $url['port']=80; }
elseif ($url['scheme'] == 'https') { $url['port']=443; }
}
$url['query']=isset($url['query'])?$url['query']:'';
$url['protocol']=$url['scheme'].'://';
$eol="\r\n";
$headers = "POST ".$url['protocol'].$url['host'].$url['path']." HTTP/1.0".$eol.
"Host: ".$url['host'].$eol.
"Referer: ".$url['protocol'].$url['host'].$url['path'].$eol.
"Content-Type: application/x-www-form-urlencoded".$eol.
"Content-Length: ".strlen($url['query']).$eol.
$eol.$url['query'];
$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
if($fp) {
fputs($fp, $headers);
$result = '';
while(!feof($fp)) { $result .= fgets($fp, 128); }
fclose($fp);
if (!$headers) {
//removes headers
$pattern="/^.*\r\n\r\n/s";
$result=preg_replace($pattern,'',$result);
}
return $result;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
Thank,goodbye :a5: