0

我正在尝试REQUEST使用此脚本捕获所有数据并保存到文本文件:

<?php 
$blocked           = array('submit');
$list              = null;
$data              = date("G:i - D.M.Y");
$hostname          = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$IPsrv             = $_SERVER['REMOTE_ADDR'];

foreach($_REQUEST as $field_name => $field_value) {
   if(!in_array($field_name, $blocked))
      $list .= "{$field_name} : {$field_value}\n";
}
$list = rtrim($list, "\n");

$fp = fopen("../data.txt", 'a');
fwrite($fp, "
================================
$list
================================");
fclose($fp); 
?>

代码有效,但我有一个问题,data.txt文件没有正确保存,我有更多NULL字符。怎样才能解决这个问题?

4

1 回答 1

0

str_replace 应该可以替换 NULL 字符吗?

fwrite($fp, "
================================
" . str_replace("\0", "", $list) . "
================================");
于 2013-10-22T22:20:45.693 回答