如何使用字段名编写POST


How to write POST with field names?

我有这个代码:

file_put_contents("123.txt", $_POST);

在txt中会有如下内容:值1值2值3

我需要这样写所有POST字段名称和值($_POST['OS'],$_POST['USRRNAME']):操作系统:Win7用户名:BLABLA

我该怎么做?

您可以使用这个:

$f = fopen("123.txt", "w");
$postArray = array_keys($_POST);            
foreach($postArray as $idx => $itemId) {            
    $v = $_POST[$itemId];
    fprintf($f, "%s: $s'n", $itemId, $v);
}
fclose($f);

如果您不关心布局,请尝试print_r():

file_put_contents("123.txt", print_r($_POST) );