note 34831 modified in function.pg-escape-bytea by danbrown
| From: | danbrown@php.net | Date: | Tue, 10 Nov 2009 15:39:09 +0000 |
| Subject: | note 34831 modified in function.pg-escape-bytea by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162706@lists.php.net to get a copy of this message | ||
to unescape_bytea use stripcslashes(). If you need to escape bytea and don't have
pg_escape_bytea() function then use:
<?php
function escByteA($binData) {
/**
* \134 = 92 = backslash, \000 = 00 = NULL, \047 = 39 = Single Quote
*
* str_replace() replaces the searches array in order. Therefore, we must
* process the 'backslash' character first. If we process it last, it'll
* replace all the escaped backslashes from the other searches that came
* before.
*/
$search = array(chr(92), chr(0), chr(39));
$replace = array('\\\134', '\\\000', '\\\047');
$binData = str_replace($search, $replace, $binData);
return $binData;
//echo "<pre>$binData</pre>";
//exit;
}
?>
--was--
to unescape_bytea use stripcslashes(). If you need to escape bytea and don't have
pg_escape_bytea() function then use:
function escByteA($binData) {
/**
* \134 = 92 = backslash, \000 = 00 = NULL, \047 = 39 = Single Quote
*
* str_replace() replaces the searches array in order. Therefore, we must
* process the 'backslash' character first. If we process it last, it'll
* replace all the escaped backslashes from the other searches that came
* before.
*/
$search = array(chr(92), chr(0), chr(39));
$replace = array('\\\134', '\\\000', '\\\047');
$binData = str_replace($search, $replace, $binData);
return $binData;
//echo "<pre>$binData</pre>";
//exit;
}
http://php.net/manual/en/function.pg-escape-bytea.php