Browscap.ini throwing an error when loading PHP (command line - PHP_CLI)
A little bit late, but there are still problems with using file without modifications. I'm using following script to download and change browscap.ini so it can work on my server.
#!/bin/sh
url="http://browscap.org/stream?q=PHP_BrowsCapINI"
curl -L -o browscap.ini ${url}
sed -I "" -E 's/;/\\;/g' browscap.ini
sed -I "" -E 's/[\\;]{40}/;;;/g' browscap.ini
sed -I "" -E "s/\'/\\\'/g" browscap.ini
mv browscap.ini /usr/local/etc/php/browscap.ini
Explanation
- 1st sed is escaping every
;
with\'
- 2nd sed is returning comments to previous state (slow), replacing just 4 or 5 semicolons will cause error because there is some section with string like this
(;;;;)
. This could be optimised with something like^\;
in search part, and just single;
in replace part, need to test that before I put - 3rd sed is escaping single quote used in "Let's encrypt..." sections and in couple other places like this
'*'
Don't forget to adjust your browscap.ini finial destination. Also there is no need for Apache or PHP restart after update, so put this script somewhere and setup cron job.
There is seemingly right now an error with those browsecap files. They seem to contain unescaped semicolons ";" in the browser spec. You can fix that using this little script:
<?php
$browsecap = file('browscap.ini');
foreach( $browsecap as &$row )
if ( $row[ 0 ] == '[' )
$row = str_replace( ';', '\\;', $row );
file_put_contents( 'fixed_browscap.ini', $browsecap );