php7过滤,转换过滤器 - PHP 7 中文文档

转换过滤器

如同 string.* 过滤器,convert.* 过滤器的作用就和其名字一样。转换过滤器是 PHP 5.0.0 添加的。对于指定过滤器的更多信息,请参考该函数的手册页。

convert.base64-encode和

convert.base64-decode使用这两个过滤器等同于分别用

[base64_encode()](php7/function.base64-encode)和

[base64_decode()](php7/function.base64-decode)函数处理所有的流数据。

convert.base64-encode支持以一个关联数组给出的参数。如果给出了

line-length,base64 输出将被用

line-length个字符为 长度而截成块。如果给出了

line-break-chars,每块将被用给出的字符隔开。这些参数的效果和用

[base64_encode()](php7/function.base64-encode)再加上

[chunk_split()](php7/function.chunk-split)相同。

Example #1 convert.base64-encode & convert.base64-decode

$fp = fopen('php://output', 'w');

stream_filter_append($fp, 'convert.base64-encode');

fwrite($fp, "This is a test.\n");

fclose($fp);

/* Outputs: VGhpcyBpcyBhIHRlc3QuCg== */

$param = array('line-length' => 8, 'line-break-chars' => "\r\n");

$fp = fopen('php://output', 'w');

stream_filter_append($fp, 'convert.base64-encode', STREAM_FILTER_WRITE, $param);

fwrite($fp, "This is a test.\n");

fclose($fp);

/* Outputs: VGhpcyBp

: cyBhIHRl

: c3QuCg== */

$fp = fopen('php://output', 'w');

stream_filter_append($fp, 'convert.base64-decode');

fwrite($fp, "VGhpcyBpcyBhIHRlc3QuCg==");

fclose($fp);

/* Outputs: This is a test. */

?>

convert.quoted-printable-encode和

convert.quoted-printable-decode使用此过滤器的 decode 版本等同于用

[quoted_printable_decode()](php7/function.quoted-printable-decode)函数处理所有的流数据。没有和

convert.quoted-printable-encode相对应的函数。

convert.quoted-printable-encode支持以一个关联数组给出的参数。除了支持和

convert.base64-encode一样的附加参数外,

convert.quoted-printable-encode还支持布尔参数

binary和

force-encode-first。

convert.base64-decode只支持

line-break-chars参数作为从编码载荷中剥离的类型提示。

Example #2 convert.quoted-printable-encode & convert.quoted-printable-decode

$fp = fopen('php://output', 'w');

stream_filter_append($fp, 'convert.quoted-printable-encode');

fwrite($fp, "This is a test.\n");

/* Outputs: =This is a test.=0A */

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值