PHP is not only a very competent web development language (and part of LAMP stack). PHP no es sólo un muy competente lenguaje de desarrollo web (y parte de la pila LAMP). It is also a very capable language for writing (command line) scripts. También es una lengua muy capaces para escribir (línea de comandos) scripts. You can write simpler and cleaner scripts with php than perl. Puede escribir más simple y menos con php scripts de 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. Aquí hay un código php que tiene un nombre de archivo como entrada, embellecedores en blanco de cada línea del archivo y, por último, guarda el resultado de vuelta en el mismo archivo.

Save the code to a file named trim.php Guardar el código a un archivo llamado 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 / / En lugar de recortar, utilice sólo con array_walk () intrim (& $ valor) ($ valor = trim ($ valor);) if ($ argc> 1) ($ archivo = file ($ argv [ 1]); array_walk ($ archivo, "intrim ');) / / Escribir a stdout / / echo implosión (" \ n ", $ archivo); / / Modificar el archivo de entrada de datos; simple pero peligrosa file_put_contents ($ argv [ 1], implosión ( "\ n", $ archivo));?> 

Run it as: Ejecutar como:
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). Yo uso este código para recortar blanco de código fuente (muchos editores innecesario introducir en blanco en los ficheros).