Reputation: 198
Given a string like this
$str = '\007\t\007\006\006\t\n\026\r\\\045';
format and output unescaped string so that
\t - tabulation
and so on.
I could solve this by using replacements, but maybe there is a better solution?
Upvotes: 1
Views: 2650
Reputation: 780889
The best I can think of is:
eval('$str_unescaped = "' . str_replace('"', '\"', $str) . '";');
str_replace
is needed in case the string contains any embedded double quotes. But it still gets an error if it contains an embedded \"
sequence.
Upvotes: 1