简体   繁体   English

PHP如何在内部表示字符串?

[英]How does PHP represent string internally?

I have basic PHP question 我有基本的PHP问题

lets say I have a string "02/03/2013", how is this represented internally in PHP, is it converted to integers or to a Hexadecimal equivalent 可以说我有一个字符串“ 02/03/2013”​​,这是如何在PHP中内部表示的,是将其转换为整数还是十六进制等效项?

when comparing two strings, how does PHP compare them internally? 比较两个字符串时,PHP如何在内部比较它们?

Thanks for the answer in advance 提前谢谢你的回答

PHP is written in C. All variables are ZVAL structs. PHP用C编写。所有变量都是ZVAL结构。

Please read these tutorials to learn more about the PHP internals and get started with writing extensions. 请阅读这些教程,以了解有关PHP内部的更多信息,并开始编写扩展。

Table 1 shows the various types, and their corresponding letter codes and C types which can be used with zend_parse_parameters(): 表1显示了可以与zend_parse_parameters()一起使用的各种类型及其对应的字母代码和C类型:

Type      Code    Variable Type
Boolean   b       zend_bool
Long      l       long
Double    d       double
String    s       char*, int
Resource  r       zval*
Array     a       zval*
Object    o       zval*
zval      z       zval*

A PHP string is just a sequence of bytes, with no encoding tagged to it. PHP字符串只是一个字节序列,没有标记任何编码。 Visit here for additional info.. 访问此处获取更多信息。

Strings are strings. 字符串是字符串。 No conversion takes place; 没有转换发生; your string just happens to contain some digits, which is fine, but PHP doesn't treat it any differently than any other string. 您的字符串恰好包含一些数字,这很好,但是PHP与其他任何字符串都没有区别。

PHP compares strings the same way that any other language would: it goes through the two strings character by character, and looks for the first pair of characters that differ. PHP以与任何其他语言相同的方式比较字符串:它逐个字符地遍历两个字符串,并查找第一对不同的字符。 Once it finds one, the string which had a character with a lower ASCII value (like you'd get from ord() ) is considered as being "less" than the other string. 一旦找到一个字符串,则该字符串的字符具有较低的ASCII值(例如,您将从ord()获得),就被认为比另一个字符串“少”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM