Search code examples
phpstringquotes

Change string enclosed in quotes to double quotes


I've got a code like this

$str = 'Hello\nThere $foo';

and I have to "convert" it like this:

$str = "Hello\nThere $foo";

Is that possible?

|EDIT| Convert as in parse it. It's being used in a cms and only accepts strings in double-quotes. But problem solved


Solution

  • If you want to interpolate the variables/escaped sequences in your string that you already have in memory, try eval():

    eval('$str = "'.$str.'";');