PHP Salt


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

Version: 2.13.2
Last Build: October 09, 2016 21:15pm (PST)

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
file_get_contents() appears to have issue sometimes with servers
that have keep-alive on. takes 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)
{
if (substr(strtolower($wFile),0,4) == "http")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $wFile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$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