How does binary file parse with php

1.

Because all the data are stored in a computer in a binary format, consider the following instruction:

$string = "welcome to $name";

If we save php file in utf-8 encoding format, the instruction would be saved in the following form:

00100100 01110011 01110100 01110010 01101001 01101110 01100111 00100000 00111101 00100000 00100010 01110111 01100101 01101100 01100011 01101111 01101101 01100101 00100000 01110100 01101111 00100000 00100100 01101110 01100001 01101101 01100101 00100010 00111011 

When I open this file in an editor, I see the letters and signs etc. correctly but how does the php interpreter see the content?

Does it see the content in this form?

00100100 01110011 01110100 01110010 01101001 01101110 01100111 00100000 00111101 00100000 00100010 01110111 01100101 01101100 01100011 01101111 01101101 01100101 00100000 01110100 01101111 00100000 00100100 01101110 01100001 01101101 01100101 00100010 00111011 

Or, does it see instructions in this form?

$string = "01110111 01100101 01101100 01100011 01101111 01101101 01100101 00100000 01110100 01101111 00100000 00100100 01101110 01100001 01101101 01100101";

or:

$string = "01110111 01100101 01101100 01100011 01101111 01101101 01100101 00100000 01110100 01101111 00100000 $name";

or:

$string = "welcome to $name";

I do not exactly know how php sees the content of a program and what is does with the data.

If it does not see the content in a binary form, so when the string or integer and other data are converted to binary format?

2.

In php files, the header of php file is set on utf-8 by default. Also, we can set the encoding process in html files by making use of charset meta-tag. Encoding method can also be changed on the browser.



Now, the question is that whether the content sent by the server as a response to a browser is in a binary format or not? If the answer is negative, what is the use of encoding?

00100100 01110011 is just a visual representation of binary numbers. Nothing is ever converted to this literal format. Your PHP codes are always remain exactly the same as you wrote them.

what is the use of encoding?

It tells the browser how to interpret the binary data it gets. In other words, what character to show when getting some binary code.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.