1

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?

4
  • 1
    I may be wrong but I don't think $str has valid characters that can be decoded. What do you expect to get as decoded string ? Commented Oct 13, 2015 at 21:05
  • 2
    whats the exact output you expected? Commented Oct 13, 2015 at 21:05
  • in output need to be string or array of raw bytes. Commented Oct 13, 2015 at 21:20
  • @RyanVincent not readable, but still characters, Commented Oct 13, 2015 at 21:39

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

it works! my string also contains '$', added str_replace(['"','$'], ['\"','\$'], $str)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.