Program (Source Code) to Trim Whitespaces from Files…程序(源代码)修剪whitespaces从档案…
PHP is not only a very competent web development language (and part of LAMP stack). PHP是不仅是一个非常能干的Web开发语言(和部分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 PHP中- F的trim.php file_to_trim
I use this code to trim whitespace from source code (many editors introduce unnecessary whitespace in files).我使用此代码修剪的空白,从源代码(许多编辑引入不必要的空白,在档案) 。
Filed under提起下 Headline News头条新闻 , , How To如何 , , PHP PHP的 , , Programming编程 , , Tech Note技术说明 , , Web网页 | |
| |
RSS 2.0 2.0 | |
Trackback Trackback跟踪 this Article |此文章|
Email this Article电子邮件此文章
You may also like to read您也可以想读 |




