From the below, how can I make the variable $new_status recognisable within those brackets?

$sendData = '{ "messages" : [ { "content" : "Your order is $new_status.", } ] }';

Problem: The above sends out text message successfully on status update, but the variable $new_status does not get updated.

I think within the those brackets php is not recognising the $new_status as a variable. I notice that if i insert one apostrophe (') just before $new_statusn like this '$new_status the variable turns green meaning it is recognised, however i get error in php that says Unexpeted T Variable

Recommended Answers

All 2 Replies

We have an open discussion on this. Let's continue there.

A string encased in single quotes means a literal string, meaning don’t evaluate any variables.

A string encased in double quotes means evaluate variables inside it.

Your entire thing is encased in single quotes. Instead, encase it in double quotes and then escape the double quotes inside (so they will be treated as literals and not prematurely close the string).

$sendData = “{ \"messages\" : [ { \"content\" : \"Your order is $new_status.\", } ] }”;

Notice the only double quotes not escaped are the ones that encapsulate the full string. All other double quotes are to be treated as literals.

Unsure what open discussion rproffitt is referring to. He didn’t post a link? Apologies if this has already been answered elsewhere.

Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.