Skip to content

Commit a5d5e10

Browse files
Pablo Joán Iglesiasserbanghita
Pablo Joán Iglesias
authored andcommitted
Update exportToJSON.php (serbanghita#576)
just a little refactoring using file_put_contents implementation instead
1 parent ccbd8d4 commit a5d5e10

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

export/exportToJSON.php

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,42 @@
2626
$detect = new Mobile_Detect;
2727

2828
$json = array(
29-
// The current version of Mobile Detect class that
30-
// is being exported.
31-
'version' => $detect->getScriptVersion(),
29+
// The current version of Mobile Detect class that
30+
// is being exported.
31+
'version' => $detect->getScriptVersion(),
3232

33-
// All headers that trigger 'isMobile' to be 'true',
34-
// before reaching the User-Agent match detection.
35-
'headerMatch' => $detect->getMobileHeaders(),
33+
// All headers that trigger 'isMobile' to be 'true',
34+
// before reaching the User-Agent match detection.
35+
'headerMatch' => $detect->getMobileHeaders(),
3636

37-
// All possible User-Agent headers.
38-
'uaHttpHeaders' => $detect->getUaHttpHeaders(),
37+
// All possible User-Agent headers.
38+
'uaHttpHeaders' => $detect->getUaHttpHeaders(),
3939

40-
// All the regexes that trigger 'isMobile' or 'isTablet'
41-
// to be true.
42-
'uaMatch' => array(
43-
// If match is found, triggers 'isMobile' to be true.
44-
'phones' => $detect->getPhoneDevices(),
45-
// Triggers 'isTablet' to be true.
46-
'tablets' => $detect->getTabletDevices(),
47-
// If match is found, triggers 'isMobile' to be true.
48-
'browsers' => $detect->getBrowsers(),
49-
// If match is found, triggers 'isMobile' to be true.
50-
'os' => $detect->getOperatingSystems(),
51-
// Various utilities. To be further discussed.
52-
'utilities' => $detect->getUtilities()
53-
)
40+
// All the regexes that trigger 'isMobile' or 'isTablet'
41+
// to be true.
42+
'uaMatch' => array(
43+
// If match is found, triggers 'isMobile' to be true.
44+
'phones' => $detect->getPhoneDevices(),
45+
// Triggers 'isTablet' to be true.
46+
'tablets' => $detect->getTabletDevices(),
47+
// If match is found, triggers 'isMobile' to be true.
48+
'browsers' => $detect->getBrowsers(),
49+
// If match is found, triggers 'isMobile' to be true.
50+
'os' => $detect->getOperatingSystems(),
51+
// Various utilities. To be further discussed.
52+
'utilities' => $detect->getUtilities()
53+
)
54+
);
5455

55-
);
56-
57-
$jsonString = function_exists('json_format') ? json_format($json) : json_encode($json);
58-
59-
// Write the JSON file to disk.
60-
// You can import this file in your app.
6156
$fileName = dirname(__FILE__).'/../Mobile_Detect.json';
62-
$handle = fopen($fileName, 'w');
63-
$fwrite = fwrite($handle, $jsonString);
64-
fclose($handle);
65-
66-
if($fwrite){
57+
// Write the JSON file to disk.11
58+
// You can import this file in your app.
59+
if (file_put_contents(
60+
$fileName,
61+
function_exists('json_format') ? json_format($json) : json_encode($json)
62+
)) {
6763
echo 'Done. Check '.realpath($fileName).' file.';
68-
} else {
64+
}
65+
else {
6966
echo 'Failed to write '.realpath($fileName).' to disk.';
70-
}
67+
}

0 commit comments

Comments
 (0)