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您也可以想讀 |



