PHP is not only a very competent web development language (and part of LAMP stack). PHP является не только весьма компетентных веб-разработки язык (и часть стека LAMP). It is also a very capable language for writing (command line) scripts. Это также очень способные язык для написания (в командной строке) скрипты. You can write simpler and cleaner scripts with php than perl. Вы можете писать простые и чистые скрипты с php, чем 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. Вот php код, который принимает имя файла в качестве вклада, СТИМ пробелы из каждой строки файла и, наконец, сохраняет результат обратно в один файл.

Save the code to a file named trim.php Сохранить код в файл с именем 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 / / В недрах отделкой, использование только с array_walk () функция intrim (и стоимостью $) ($ = стоимость отделки ($ стоимость);), если ($ argc> 1) ($ = файл-файл ($ argv [ 1]); array_walk ($ файл, 'intrim');) / / Пишите вывода / / эхо implode ( "\ n", $-файл) / / Изменить файл ввода данных; опасный, но простой file_put_contents ($ argv [ 1], implode ( "\ n", $-файл));?> 

Run it as: Запустите его, как:
php -f trim.php file_to_trim путь к ж trim.php file_to_trim

I use this code to trim whitespace from source code (many editors introduce unnecessary whitespace in files). Я использую этот код для подрезки пробел от исходного кода (многие редакторы вводить ненужные пробелы в файлах).