I need to get the Name and Version of all packages in a Packages file (Packages.gz
) that's from a Cydia debian repo that I have, I'm trying to find the best way to do it in PHP.
I'm new to PHP and learning it as I go to make a small project for myself but haven't been able to find a example that I can understand. I found this while searching and it gets what I need but it's not PHP.
awk -F": " ' /^Package/{p=$2;getline;v=$2;getline;f=$2;ary[p"\n"v"\n"]} END{for (x in ary) print x}' file
You could use the ZLib functions in PHP to read the file directly...
<?php
error_reporting ( E_ALL );
ini_set ( 'display_errors', 1 );
$file = gzopen('Packages.gz', 'r');
while ( $line = gzgets($file)) {
if ( substr($line, 0,8) == 'Package:' ||
substr($line, 0,8) == 'Version:') {
echo $line;
}
}