What does the b in front of string literals do?(字符串字面量前面的 b 有什么作用?)
问题描述
$binary = b'Binary string';
将字符串创建为 b
inary 有什么后果?
What consequences does it have to create a string as b
inary?
我在文档中找不到任何关于此的提示.刚刚在浏览 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 有什么作用?


- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01