PHP is not only a very competent web development language (and part of LAMP stack). PHP non è solo una competenti sviluppo web lingua (e parte di stack LAMP). It is also a very capable language for writing (command line) scripts. E 'anche una lingua molto capace per iscritto (riga di comando) script. You can write simpler and cleaner scripts with php than perl. È possibile scrivere più semplice e pulito con PHP script di perl. Here is a php code which takes a file name as input, trims whitespace from each line of the file and finally saves the result back in the same file. Qui è un codice php che prende un nome di file come input, trim spazi da ogni riga del file e, infine, salva il risultato ritornare nello stesso file.

Save the code to a file named trim.php Salvare il codice in un file chiamato trim.php

 < ?php // In-place trim, use only with array_walk() function intrim(&$value) {   $value = trim($value); } if($argc > 1) {   $file = file($argv[1]);   array_walk($file, ‘intrim’); } // Write to stdout //echo implode(”\n”, $file);  // Modify the input file data; dangerous but simple file_put_contents($argv[1], implode(”\n”, $file)); ?> <? Php / / In-trim luogo, utilizzare solo con array_walk () intrim (& $ value) ($ value = trim ($ value);) if ($ argc> 1) ($ file = file ($ argv [ 1]); array_walk ($ file, 'intrim');) / / scrittura su stdout / / echo implode ( "\ n", $ file); / / Modifica il file di input dei dati; pericolose, ma semplice file_put_contents ($ argv [ 1], implode ( "\ n", $ file));?> 

Run it as: Eseguirlo come:
php -f trim.php file_to_trim PHP-f trim.php file_to_trim

I use this code to trim whitespace from source code (many editors introduce unnecessary whitespace in files). Utilizzare questo codice per trim spazi da codice sorgente (molti editori di introdurre inutili spazi nei file).