I have a challenge that I have a hard time describing it in a short web search. I'm hoping if I can successfully explain it long form all the experts here can understand what I'm asking and let me know if this is even possible. This is theoretical/academic question, not a troubleshooting question.
Say I have a string in a SQL Table that looks like this:
"Hi my name is $name, very please to meet you!"
In my PHP code I have a variable $name
with a value in it. If I manually copy this string into my PHP code, interpolation works as advertised and all is good. But if my script uses mysqli to fetch this string I end up with a string that doesn't interpolate, which I guess sort of makes sense, maybe. My question is, is there a way to force that string to interpolate?
I tried to parse out the variable name, in which case I ended with $varname="$name"
and whenever I tried to print $varname
I always got $name
, not the value of $name
. Am I barking up the wrong tree here, is this even possible? Should I be looking for an different ways to accomplish this, like store this string in two parts "Hi my name is " in one table field and ", very please to meet you!" in a different table field and then concatenate all three strings together like:
print "$dbstring1 . $name . $dbstring2";
Naturally this isn't the actual string I'm working with, just trying to keep things simple as this is more of a theoretical/academic question than a troubleshooting question.