将变量解析为字符串文字

I have some string in a variable that I don't control.

$foo = 'hey man';

(notice the single quotes, it's a literal not the new line character)

Now I would like to have foo parsed as if it were inside a double quotes instead of single. So it would convert the literal escape characters to their corresponding ascii characters. All of then /r, /n, /b, /t, etc.

I have access to $foo but I can't change the code that assigns it's value to it. My option is a regex but that can get ugly with many number of different characters possible. I like how neatly php handles it and was wondering if I can leverage it.

You can use eval:

$foo = 'hey
man';
eval ('$b = "' . $foo . '";');
var_dump($b);

You can also use string replace

$foo = str_replace('
', "
", $foo);