Yeah the only reason I mentioned single and double quotes is because I can't find the words to explain what I'm saying. So I couldn't google this problem either.
The user isn't supplying any other text. That comes from elsewhere.
I think the commonly used term for them is still just single quoted and double quoted string literals, but I think double quoted string literals are also referred to as something like variable-parsed string literals. Unfortunately I'm pretty sure there's no simple way to parse a string variable in the same way that a double quoted string literal is parsed by PHP.
I think the closest you're going to get to exactly what you were looking for is by using
, which is very undesirable because it can literally run any maliciously injected code if the user knows how the variable is eval'd by your code. But this line of code will do what you're looking for:
eval("\$str = \"$str\";");
In the end, though, I think your solution of just replacing characters in the string is probably simpler and safer.