The only way I found string interpolation (IE to expand variables inside it) is this:
$str = 'This is a $a'; $a = 'test'; echo eval('return "' . $str . '";');
Keep in mind that in a real scenario, strings are created in different places, so I can’t just replace ' s with ' s.
Is there a better way to expand a single quote string without using eval ()? I am looking for something that PHP itself provides.
Pay attention . Using strtr () is similar to using sprintf (). My question is different from the question related to a possible duplicate section of this question, since I allow the line to control how (IE through which calls to functions or property accessories) it wants to receive content.
source share