Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/phpbrowscap/Browscap.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,22 +814,37 @@ protected function _getRemoteIniFile($url, $path)
// Get updated .ini file
$browscap = $this->_getRemoteData($url);

// $browscap = explode("\n", $browscap);

$browscap = explode("\n", $browscap);
$tmppath = $path.'.tmp';
if (!file_put_contents($tmppath, $browscap)) {
throw new Exception("Could not write temp .ini content to $path");
}
unset($browscap);

$pattern = self::REGEX_DELIMITER
. '('
. self::VALUES_TO_QUOTE
. ')="?([^"]*)"?$'
. self::REGEX_DELIMITER;


$content = '';
$fh = fopen($tmpath,'r');
while (!feof($fh)) {
$subject = trim(fgets($fh));
$content .= preg_replace($pattern, '$1="$2"', $subject) . "\n";
}
if (!file_put_contents($path, $content)) {
throw new Exception("Could not write .ini content to $path");
}
@unlink($tmppath);

// Ok, lets read the file
$content = '';
foreach ($browscap as $subject) {
$subject = trim($subject);
$content .= preg_replace($pattern, '$1="$2"', $subject) . "\n";
}
// $content = '';
// foreach ($browscap as $subject) {
// $subject = trim($subject);
// $content .= preg_replace($pattern, '$1="$2"', $subject) . "\n";
// }

if ($url != $path) {
if (!file_put_contents($path, $content)) {
Expand Down