將數組打印到txt文件中


用print_r 將數組打印到txt文件中。

復制代碼
 
 
1、
function save_log($content='', $file='app') {
$logDir = './logs';
$now = date('Y');
$nowDir = $logDir.'/'.$now;
if(!is_dir($nowDir)) {
mkdir($nowDir, 0777, true);
chmod($nowDir, 0777);
}
$fileDir = $nowDir.'/'.$file.'.log';
// chmod($file.'.log', 0777);
file_put_contents($fileDir, date('Y-m-d H:i:s').PHP_EOL, FILE_APPEND);
$results = print_r($content, true);
file_put_contents($fileDir, print_r($content, true), FILE_APPEND);
file_put_contents($fileDir, PHP_EOL, FILE_APPEND);
}
 
2、
<?php
$b = array (
    'm' => 'monkey', 
    'foo' => 'bar', 
    'x' => array ('x', 'y', 'z'));

$results = print_r($b, true); 
file_put_contents('filename.txt', print_r($b, true));
?>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM