I need to pass the data from varlable saved1 into reply_message (line 45) and it doesn't work
I've tried " {"text": "${saved1}"} but nothing response.
the result expected are "text": "line1 \n 123 \n line 3"
Output
line 1
123
line 3
Any help are appreciate Thanks & Regards
<?php
send_reply($access_token,$reply_message);
$reply_message='{
"messaging_type": "RESPONSE",
"recipient": {
"id": "1631126643573991"
},
"message": {
"text": "line1 \n $saved1 \n line 3"
}
}';
send_reply($access_token,$reply_message);
}
function send_reply($access_token='',$reply='')
{
$url="https://graph.facebook.com/v14.0/me/messages?access_token=$access_token";
$ch = curl_init();
$headers = array("Content-type: application/json");
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$reply);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$st=curl_exec($ch);
$result=json_decode($st,TRUE);
return $result;
}
?>
CodePudding user response:
Use concatenation for $saved1 like below.
$reply_message='{
"messaging_type": "RESPONSE",
"recipient": {
"id": "1631126643573991"
},
"message": {
"text": "line1 \n '.$saved1.' \n line 3"
}
}';