What does the b in front of string literals do?(字符串字面量前面的 b 有什么作用?)
问题描述
$binary = b'Binary string';
将字符串创建为 binary 有什么后果?
What consequences does it have to create a string as binary?
我在文档中找不到任何关于此的提示.刚刚在浏览 language_scanner 时发现了这个小小的好奇心.
I couldn't find any hint about that in the documentation. Just found this little curiosity while looking through the language_scanner.
推荐答案
这是一个前向兼容性令牌,适用于永远不会发布的 PHP 版本 6,它应该具有本机 unicode 支持.
This is a forward compatibility token for the never-to-be-released PHP version 6, which should have had native unicode support.
在 PHP6 中,字符串默认为 unicode,函数在 unicode 字符级别对其进行操作.这个b"的意思是二进制字符串",即非unicode字符串,函数在字节级别对它进行操作.
In PHP6, strings are unicode by default, and functions operate at the unicode character level on them. This "b" means "binary string", that is, a non unicode string, on which functions operate at the byte level.
这在 PHP != 6 中无效,其中所有字符串都是二进制的.
This has no effect in PHP != 6, where all strings are binary.
这篇关于字符串字面量前面的 b 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:字符串字面量前面的 b 有什么作用?
基础教程推荐
- php中的PDF导出 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的foreach复选框POST 2021-01-01
- Web 服务器如何处理请求? 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
