note 86044 added to language.types.string

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Simple function to create human-readably escaped double-quoted strings for use in source code or when debugging strings with newlines/tabs/etc.

<?php
function doubleQuote($str) {
    $ret = '"';
    for ($i = 0, $l = strlen($str); $i < $l; ++$i) {
        $o = ord($str[$i]);
        if ($o < 31 || $o > 126) {
            switch ($o) {
                case 9: $ret .= '\t'; break;
                case 10: $ret .= '\n'; break;
                case 11: $ret .= '\v'; break;
                case 12: $ret .= '\f'; break;
                case 13: $ret .= '\r'; break;
                default: $ret .= '\x' . str_pad(dechex($o), 2, '0', STR_PAD_LEFT);
            }
        } else {
            switch ($o) {
                case 36: $ret .= '\$'; break;
                case 34: $ret .= '\"'; break;
                case 92: $ret .= '\\\\'; break;
                default: $ret .= $str[$i];
            }
        }
    }
    return $ret . '"';
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 128.227.34.143
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit        -- https://master.php.net/note/edit/86044
Del: integrated  -- https://master.php.net/note/delete/86044/integrated
Del: useless     -- https://master.php.net/note/delete/86044/useless
Del: bad code    -- https://master.php.net/note/delete/86044/bad+code
Del: spam        -- https://master.php.net/note/delete/86044/spam
Del: non-english -- https://master.php.net/note/delete/86044/non-english
Del: in docs     -- https://master.php.net/note/delete/86044/in+docs
Del: other reasons-- https://master.php.net/note/delete/86044
Reject      -- https://master.php.net/note/reject/86044
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.