2

I have basic PHP question

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

when comparing two strings, how does PHP compare them internally?

Thanks for the answer in advance

1

3 Answers 3

4

PHP is written in C. All variables are ZVAL structs.

Please read these tutorials to learn more about the PHP internals and get started with writing extensions.

Table 1 shows the various types, and their corresponding letter codes and C types which can be used with zend_parse_parameters():

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*
Sign up to request clarification or add additional context in comments.

2 Comments

Does the int that goes along the char * represent the size of the string - ie the string would not need to be \0 terminated?
@ring0 That's 100% right, a string in php doesn't need to be \0 terminated :)
1

A PHP string is just a sequence of bytes, with no encoding tagged to it. Visit here for additional info..

Comments

0

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 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. 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.

1 Comment

You may want to make a comment about strcmp and related functions for advanced string comparison.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.