3 ms·
With projects like composer/symfony/laravel & the plethora of really good PHP packages out there, it is easy to write a good CLI with PHP these days.
by tomschlick 10y ago
With projects like composer/symfony/laravel & the plethora of really good PHP packages out there, it is easy to write a good CLI with PHP these days.
- cutler 10y agoSimple text parsing in PHP7 is also faster than in Python, Ruby, Perl and NodeJS. I recently wrote some 1-liners to parse a 19Mb log file with a regex on my 2010 quad-core Mac. Python/Ruby: 2.2 secs. Perl: 1.4 secs. NodeJS: 0.9 secs. PHP7: 0.4 secs.
- iso-8859-1 10y agoCan you show your code, at least?
- cutler 10y agoSure: Ruby IO.foreach('logs1.txt') {|x| puts x if /\b\w{15}\b/.match? x } Python3 import re with open('logs1.txt', 'rt') as fh: for line in fh: if re.search(r'\b\w{15}\b', line): print(line, end=' ') Perl open my $fh, '<', 'logs1.txt'; while (<$fh>) { chomp; say if $_ =~ /\b\w{15}\b/; } close $fh; NodeJS var fs = require('fs'), byline = require('byline'); var stream = byline(fs.createReadStream('logs1.txt', {encoding: 'utf8'})); stream.on('data', function(line) { if (line.match(/\b\w{15}\b/)) console.log(line); }); PHP $fh = fopen('logs1.txt', 'r'); while (($line = fgets($fh)) !== false) { if (preg_match('/\b\w{15}\b/', $line)) echo $line; } fclose($fh);