How can I use php string inside this Json array ? I want to replace the name "john" according php string. but whatever I do it is getting treated as plane text.
I tried "text": "'.$fullname.'" and even "text": ""
It is used code for 360dialog Whatsapp API.
$payload = <<<'PAYLOAD'
{
"to": "911212121212",
"type": "template",
"template": {
"namespace": "56n9828435v89248-57498240734",
"language": {
"policy": "deterministic",
"code": "en"
},
"name": "new_booking",
"components": [{
"type": "body",
"parameters": [{
"type": "text",
"text": "john"
},
{
"type": "text",
"text": "Hair Cutting"
},
{
"type": "text",
"text": "17/11/2022"
},
{
"type": "text",
"text": "04:00 PM"
}
,
{
"type": "text",
"text": "http://www.google.com"
}
]
}
]
}
}
PAYLOAD;
https://docs.360dialog.com/docs/whatsapp-api/whatsapp-api/sandbox#php
json_encode()to encode it into json. Not only does it remove the risk of typos that could cause invalid JSON, but you can then just add the variable as the value for the element you want, just like you would for any other PHP variable.<<<"PAYLOAD"or just<<<PAYLOADto make it work.