Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make work variable inside curl function (PHP)

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"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
    }

?>

>Solution :

Use concatenation for $saved1 like below.

$reply_message='{

            "messaging_type": "RESPONSE",
            "recipient": {
                "id": "1631126643573991"
                },
            "message": {
                "text": "line1 \n '.$saved1.' \n line 3"
                }
        }';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading