note 105967 added to function.pg-escape-bytea

From: Date: Wed, 28 Sep 2011 21:31:45 +0000
Subject: note 105967 added to function.pg-escape-bytea
Groups: php.notes 
Request: Send a blank email to php-notes+get-183512@lists.php.net to get a copy of this message
If you want to use pg_escape_bytea and have no pgsql extension, or if you want old-style escaping(see https://bugs.php.net/bug.php?id=53127 for details) you can use function pg_escape_bytea($str) { $raw = unpack('C*', $str); $res = ''; foreach ($raw as $charcode) { if ($charcode < 0x20 || $charcode > 0x7e) { $res .= '\\\\' . ($charcode >> 6); $res .= ($charcode >> 3) & 0x07; $res .= $charcode & 0x07; } elseif ($charcode === 0x27){ $res .= "''"; } elseif ($charcode === 0x5c) { $res .= '\\\\\\\\'; } else { $res .= chr($charcode); } } return $res; } It is based on PQescapeByteaInternal function from PostgreSQL 9.0.4 sources. NB: this function depends on 'standard_conforming_strings' setting of PostgreSQL, it must be set to off. If you want to set it to on, halve escaping slashes number. ---- Server IP: 69.147.83.197 Probable Submitter: 176.14.83.209 ---- Manual Page -- http://www.php.net/manual/en/function.pg-escape-bytea.php Edit -- https://master.php.net/note/edit/105967 Del: integrated -- https://master.php.net/note/delete/105967/integrated Del: useless -- https://master.php.net/note/delete/105967/useless Del: bad code -- https://master.php.net/note/delete/105967/bad+code Del: spam -- https://master.php.net/note/delete/105967/spam Del: non-english -- https://master.php.net/note/delete/105967/non-english Del: in docs -- https://master.php.net/note/delete/105967/in+docs Del: other reasons-- https://master.php.net/note/delete/105967 Reject -- https://master.php.net/note/reject/105967 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183512) next »