今天寫了如下代碼發現 制表符 \t在 單引號 和 雙引號下有差異。
$name = 'keygle'; $age = '24'; $sex = '男'; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; $date = date("Y-m-d H:i:s"); //$outputstring = $date." 姓名:\t".$name." 年齡:\t".$age." 性別:\t".$sex."\n"; //這里使用雙引號 $outputstring = $date.' 姓名:\t'.$name.' 年齡:\t'.$age.' 性別:\t'.$sex.'\n'; //這里使用單引號 只能輸出\t $fp = fopen($DOCUMENT_ROOT.'../order/desire.txt','ab'); flock($fp,LOCK_EX); fwrite($fp,$outputstring,strlen($outputstring)); flock($fp,LOCK_UN); fclose($fp);
顯示效果 分別為
單引號 :
2012-09-07 11:53:33 姓名:\tkeygle 年齡:\t24 性別:\t男\n
雙引號:
2012-09-07 11:55:17 姓名: keygle 年齡: 24 性別: 男
單引號下 制表符沒有解析不知道為什么。。。。。。