大网数据广告活动
PHP 语言与运行手册

pg_unescape_bytea · 反转义 bytea 类型的二进制数据

· 52CE 我爱测

pg_unescape_bytea() 反转义 PostgreSQL bytea 数据值。返回反转义后的字符串,可能包含二进制数据。

pg_unescape_bytea

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

pg_unescape_bytea — 反转义 bytea 类型的二进制数据

说明

function pg_unescape_bytea(string $string): string

pg_unescape_bytea() 反转义 PostgreSQL bytea 数据值。返回反转义后的字符串,可能包含二进制数据。

注意:

当 SELECT bytea 类型时,PostgreSQL 返回前缀为“\”的八进制字节值(例如 \032)。用户需要手动将其转换回二进制格式。

参数

string

string,包含 PostgreSQL bytea 数据,需要转换为 PHP 二进制字符串。

返回值

包含反转义数据的 string。

示例

示例 #1 pg_unescape_bytea() 示例

<?php 
  // Connect to the database
  $dbconn = pg_connect('dbname=foo');
  
  // Get the bytea data
  $res = pg_query("SELECT data FROM gallery WHERE name='Pine trees'");  
  $raw = pg_fetch_result($res, 'data');
  
  // Convert to binary and send to the browser
  header('Content-type: image/jpeg');
  echo pg_unescape_bytea($raw);
?>

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。