Search code examples
phpjsonvariablesvar

I would like php to "execute" a variable into a string


I use JSON to organize my PHP code.

I don't know if it's possible but I stocked inside of my Json a PHP variable. I would like to get it in my PHP script.

I've created my JSON file :

{
    "link" : "?id=$org_id"
}

In my php, I use the json_decode function. Then in PHP, I stock the result in a variable

Thus,

$org_id = 456;
echo $res; //output "?id=$org_id" while I wanted "?id=456"

What can I do?


Solution

  • echo strtr($res, array('$org_id' => $org_id));

    Should substitute the string '$org_id' with the variable $org_id