November 3, 2009
decompress gz with php
Category: PHP, Tags: exec, gunzip, gzip, PHP, khadlock at 9:14 pm
I had a lot of trouble getting zlib to work today with PHP on our Media Temple DV server, but after a lot of testing discovered an easy solution to decompressing/unzipping .gz files.
exec("gunzip Filename.gz", $results);
Once decompressed I can read the file contents using fopen, file_get_contents, etc.
More information on the gzip commands can be found at http://en.wikipedia.org/wiki/Gzip
November 2, 2009
Remove empty array values in PHP
Category: PHP, Tags: PHP, khadlock at 7:51 pm
Here's a super easy way to remove empty values from an array in PHP:
$a = array_diff($a, array(""));
In a recent project we were reading in a text file and creating an array based on each new line, so we used the same method to remove any new lines that were empty.
$a = array_diff($a, array("\n"));
« Newer Posts
