public static function unescape($s)
    {
        $out = '';
        /** @noinspection ForeachInvariantsInspection */
        for ($count = 0, $n = \strlen($s); $count < $n; $count++) {
            if ($s[$count] !== '\\') {
                $out .= $s[$count];
            } else {
                // A backslash at the end of the string - ignore it
                if ($count === ($n - 1)) {
                    break;
                }

                switch ($s[++$count]) {
                    case ')':
                    case '(':
                    case '\\':
                        $out .= $s[$count];
                        break;

                    case 'f':
                        $out .= "\x0C";
                        break;

                    case 'b':
                        $out .= "\x08";
                        break;

                    case 't':
                        $out .= "\x09";
                        break;

                    case 'r':
                        $out .= "\x0D";
                        break;

                    case 'n':
                        $out .= "\x0A";
                        break;

                    case "\r":
                        if ($count !== $n - 1 && $s[$count + 1] === "\n") {
                            $count++;
                        }
                        break;

                    case "\n":
                        break;

                    default:
                        $actualChar = \ord($s[$count]);
                        // ascii 48 = number 0
                        // ascii 57 = number 9
                        if ($actualChar >= 48 &&
                            $actualChar <= 57) {
                            $oct = '' . $s[$count];

                            /** @noinspection NotOptimalIfConditionsInspection */
                            if ($count + 1 < $n &&
                                \ord($s[$count + 1]) >= 48 &&
                                \ord($s[$count + 1]) <= 57
                            ) {
                                $count++;
                                $oct .= $s[$count];

                                /** @noinspection NotOptimalIfConditionsInspection */
                                if ($count + 1 < $n &&
                                    \ord($s[$count + 1]) >= 48 &&
                                    \ord($s[$count + 1]) <= 57
                                ) {
                                    $oct .= $s[++$count];
                                }
                            }

                            $out .= \chr(\octdec($oct));
                        } else {
                            // If the character is not one of those defined, the backslash is ignored
                            $out .= $s[$count];
                        }
                }
            }
        }
        return $out;
    }
public static function unescape($s)
    {
        $out = '';
        /** @noinspection ForeachInvariantsInspection */
        for ($count = 0, $n = \strlen($s); $count < $n; $count++) {
            if ($s[$count] !== '\\') {
                $out .= $s[$count];
            } else {
                // A backslash at the end of the string - ignore it
                if ($count === ($n - 1)) {
                    break;
                }

                switch ($s[++$count]) {
                    case ')':
                    case '(':
                    case '\\':
                        $out .= $s[$count];
                        break;

                    case 'f':
                        $out .= "\x0C";
                        break;

                    case 'b':
                        $out .= "\x08";
                        break;

                    case 't':
                        $out .= "\x09";
                        break;

                    case 'r':
                        $out .= "\x0D";
                        break;

                    case 'n':
                        $out .= "\x0A";
                        break;

                    case "\r":
                        if ($count !== $n - 1 && $s[$count + 1] === "\n") {
                            $count++;
                        }
                        break;

                    case "\n":
                        break;

                    default:
                        $actualChar = \ord($s[$count]);
                        // ascii 48 = number 0
                        // ascii 57 = number 9
                        if ($actualChar >= 48 &&
                            $actualChar <= 57) {
                            $oct = '' . $s[$count];

                            /** @noinspection NotOptimalIfConditionsInspection */
                            if ($count + 1 < $n &&
                                \ord($s[$count + 1]) >= 48 &&
                                \ord($s[$count + 1]) <= 57
                            ) {
                                $count++;
                                $oct .= $s[$count];

                                /** @noinspection NotOptimalIfConditionsInspection */
                                if ($count + 1 < $n &&
                                    \ord($s[$count + 1]) >= 48 &&
                                    \ord($s[$count + 1]) <= 57
                                ) {
                                    $oct .= $s[++$count];
                                }
                            }

                            $out .= \chr(\octdec($oct));
                        } else {
                            // If the character is not one of those defined, the backslash is ignored
                            $out .= $s[$count];
                        }
                }
            }
        }
        return $out;
    }
public static function unescape ( $ s ) { $ out = '' ; /** @noinspection ForeachInvariantsInspection */ for ( $ count = 0 , $ n = \ strlen ( $ s ) ; $ count < $ n ; $ count ++ ) { if ( $ s [ $ count ] !== '\\' ) { $ out .= $ s [ $ count ] ; } else { // A backslash at the end of the string - ignore it if ( $ count === ( $ n - 1 ) ) { break ; } switch ( $ s [ ++ $ count ] ) { case ')' : case '(' : case '\\' : $ out .= $ s [ $ count ] ; break ; case 'f' : $ out .= "\x0C" ; break ; case 'b' : $ out .= "\x08" ; break ; case 't' : $ out .= "\x09" ; break ; case 'r' : $ out .= "\x0D" ; break ; case 'n' : $ out .= "\x0A" ; break ; case "\r" : if ( $ count !== $ n - 1 && $ s [ $ count + 1 ] === "\n" ) { $ count ++ ; } break ; case "\n" : break ; default : $ actualChar = \ ord ( $ s [ $ count ] ) ; // ascii 48 = number 0 // ascii 57 = number 9 if ( $ actualChar >= 48 && $ actualChar <= 57 ) { $ oct = '' . $ s [ $ count ] ; /** @noinspection NotOptimalIfConditionsInspection */ if ( $ count + 1 < $ n && \ ord ( $ s [ $ count + 1 ] ) >= 48 && \ ord ( $ s [ $ count + 1 ] ) <= 57 ) { $ count ++ ; $ oct .= $ s [ $ count ] ; /** @noinspection NotOptimalIfConditionsInspection */ if ( $ count + 1 < $ n && \ ord ( $ s [ $ count + 1 ] ) >= 48 && \ ord ( $ s [ $ count + 1 ] ) <= 57 ) { $ oct .= $ s [ ++ $ count ] ; } } $ out .= \ chr ( \ octdec ( $ oct ) ) ; } else { // If the character is not one of those defined, the backslash is ignored $ out .= $ s [ $ count ] ; } } } } return $ out ; }
Unescapes escaped sequences in a PDF string according to the PDF specification.

@param string $s
@return string
Unescapes escaped sequences in a PDF string according to the PDF specification .