dongling3243 2016-08-10 07:21
浏览 80
已采纳

从gzdeflate复制/粘贴多字节字符串?

Take the output of gzdeflate(), for example:

$a = gzdeflate('..........');
echo $a . "
" . strlen($a);

I get output like:

?Ӄ
5

So I've got a 5 byte string that contains characters which cannot be outputted properly, and hence cannot be copy and pasted.

Obviously, echo gzinflate('?Ӄ'); doesn't work, but echo gzinflate($a) does.

Is there any way to get the actual contents of $a onto my clipboard or output it in such a way that I could copy and paste it into gzinflate() to retrieve the original string? The only workaround I've found is something like:

$a = base64_encode(gzdeflate('..........'));
echo $a;

Which gives me:

09ODAQA=

That's friendly enough to do echo gzinflate(base64_decode('09ODAQA=')); and get .........., but I'd like to skip the base64 functions if possible.

  • 写回答

2条回答 默认 最新

  • duanhuokuang5280 2016-08-10 07:28
    关注

    The problem is that you're channeling binary data through a text medium. If you require the data to be printed out on your screen where you will select and copy it, there's no way to transport binary data like that.

    If this is happening on the command line, you could do it programatically without displaying the actual contents. Take OS X's pbcopy and pbpaste commands:

    $ php test.php | pbcopy
    $ pbpaste | someotherprogram
    

    If you do require a visible textual representation, you need to ensure that the output is ASCII-safe (or at least "Unicode safe") and not raw binary data. For that you will need to base 64 or hex encode your binary data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?