PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.20.11
Last Build: November 09, 2018 12:24pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
file
graph
html
mail
math
misc
mobile
script
string
system
time
psFileGetContents()
Reads file/url into String


Description:

This is used to replace file_get_contents()

Just a wrapper if local file, but uses CURL if a http(s) url

updated: 2.20.6
To speed things up, we reuse the curl object and this fixed
the issue sometimes with servers that have keep-alive on, it
would take a while to clsoe connection.



Usage:


$varFloat = psFileGetContents(URL|FILE,FLAG_TRIM);

FLAG_TRIM
true - the default, uses trim() on the return string
false - do not trim the return string (usefull for binary data)



Example:


$strPage = psFileGetContents("http://www.google.com");



Code:



function psFileGetContents($wFile,$flgTrim=true)
{
global $_PHPSALT;
// curl reuse added
if (substr(strtolower($wFile),0,4) == "http")
{
if ( $_PHPSALT['global/curl'] == false )
{
$ch = curl_init();
$_PHPSALT['global/curl'] = $ch;
}
else
{
$ch = $_PHPSALT['global/curl'];
}
curl_setopt($ch, CURLOPT_URL, $wFile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING,'');
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$buffer = curl_exec($ch);
//curl_close($ch);
}
else
{
$buffer = @file_get_contents($wFile);
}


if ($flgTrim == true) { $buffer = trim($buffer); }
return $buffer;
}

Changlelog:


See Also

  psFile_gc()
And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site