Last active
November 1, 2019 22:04
-
-
Save xoxefdp/e74ef30ca4721f2588367e2de8ebe553 to your computer and use it in GitHub Desktop.
Fixes wrong formatted browsercap.ini file from https://browscap.org (PHP Versions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://browscap.org/stream?q=Full_PHP_BrowsCapINI | |
$full_php_browscap = file('full_php_browscap.ini'); | |
// Let\'s Encrypt flag | |
$count = 0; | |
foreach( $full_php_browscap as &$row ) { | |
if ( $row[ 0 ] == '[' ) { | |
$row = str_replace( ';', '\\;', $row ); | |
} | |
// Let\'s Encrypt single quote | |
if ( ( strpos($row, "'") !== false ) && ( $count < 3 ) ) { | |
$row = str_replace( "'", "\\'", $row ); | |
$count++; | |
} | |
} | |
file_put_contents( 'browscap.ini', $full_php_browscap ); | |
echo 'Fixing full_php_browscap.ini to browscap.ini DONE'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://browscap.org/stream?q=Lite_PHP_BrowsCapINI | |
$lite_php_browscap = file('lite_php_browscap.ini'); | |
// Let\'s Encrypt flag | |
$count = 0; | |
foreach( $lite_php_browscap as &$row ) { | |
if ( $row[ 0 ] == '[' ) { | |
$row = str_replace( ';', '\\;', $row ); | |
} | |
// Let\'s Encrypt single quote | |
if ( ( strpos($row, "'") !== false ) && ( $count < 3 ) ) { | |
$row = str_replace( "'", "\\'", $row ); | |
$count++; | |
} | |
} | |
file_put_contents( 'browscap.ini', $lite_php_browscap ); | |
echo 'Fixing lite_php_browscap.ini to browscap.ini DONE'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://browscap.org/stream?q=PHP_BrowsCapINI | |
$php_browscap = file('php_browscap.ini'); | |
// Let\'s Encrypt flag | |
$count = 0; | |
foreach( $php_browscap as &$row ) { | |
if ( $row[ 0 ] == '[' ) { | |
$row = str_replace( ';', '\\;', $row ); | |
} | |
// Let\'s Encrypt single quote | |
if ( ( strpos($row, "'") !== false ) && ( $count < 3 ) ) { | |
$row = str_replace( "'", "\\'", $row ); | |
$count++; | |
} | |
} | |
file_put_contents( 'browscap.ini', $php_browscap ); | |
echo 'Fixing php_browscap.ini to browscap.ini DONE'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using get_browser()
PHP actually has a built-in method of parsing the browscap.ini file. However, for this method you must manually download the correct browscap.ini (any of the PHP versions) and configure PHP for the correct directory.
To use get_browser() on PHP a browscap.ini is required.