復制代碼 代碼如下:
<?php /* *讀取文件內容至字符串中,同時去除換行、行首行尾空格。 */ header("Content-type: text/html; charset=utf-8"); echo preg_replace('/((\s)*(\n)+(\s)*)/i',',',file_get_contents('./file.php'));//End_php
//輸出:
aaaa,bbbb,cccc,dddd,eeee,ffff,gggg,hhhh,iiii,jjjj,kk kk,ll ll
//file.php內容:
aaaa
cccc
dddd
eeee
ffff
gggg
hhhh
iiii
jjjj
kk kk
ll ll
//file.php替換空格(x)、Tab(T)效果
aaaa
TTTT
cccc
ddddT
xxxxxxxxxxxT
eeeexxxxxxxxxx
ffff
gggg
hhhhxxxxxxxx
xxxxxxxxiiii
xxxxxxxxjjjjxxxxxxx
kkxxxkkTT
xxxxllxxllTT
Txxxxxxxxxx
TTTxx