我正在设置一个网络钩子处理程序,接收一个帖子。由于我没有将数据存储在数据库中,所以我只需要将数据打印到文本文件中,以查看所有内容,使用
file_put_contents(dirname(__FILE__)."/response.txt", $test_file, FILE_APPEND);$_POST‘’data_json‘;返回以下对象
{ "time_submitted":"11:47 PM UTC“,"page_uuid":"657773c0-596b-4cad-b2f6-7e1e197f4df4”,"phone_number":"3335553344“,"estimated_move_date":"09/29/2020”,“电子邮件”:"toweltest@test.com“,"page_name":”测试页“,”utm_adgroup:“,"date_submitted":"2020-09-16“、”名称“:”毛巾测试“、”源“:"AdWords”、"utm_campaign":“utm_campaign”、"ip_address":"33.333.333.333“、"page_url":"utm_term":"”、“utm_term”:"“、”变体“:"a”}
因此,我将$_POST‘’data_json‘设置为一个变量
$test_file = $_POST['data_json'];我尝试将$test_ file ->电子邮件打印到文件中,但没有打印任何内容。
$email = $test_file->email;
file_put_contents(dirname(__FILE__)."/response.txt", $email, FILE_APPEND);我一直在编码和解码,并试图找出我的格式有什么问题。有什么建议吗?
发布于 2020-09-17 01:10:12
尝尝这个
if your post data is $test_file = $_POST['data_json'];
$data = json_decode($test_file);
$email = $data->email;
file_put_contents(dirname(__FILE__)."/response.txt", $email, FILE_APPEND);如果仍然看到问题,请检查目录权限。
发布于 2020-09-17 05:55:59
来源:
$dataJsonStr = $_POST['data_json'];
$data = json_decode($dataJsonStr);
var_dump($data->email);
var_dump($data->email[0]);结果:
array(1) {
[0]=>
string(18) "toweltest@test.com"
}
string(18) "toweltest@test.com"原始$data->email是一个数组,它可能包含多个项。使用前一定要检查数组。
https://stackoverflow.com/questions/63929421
复制相似问题