A strange problem occurred when passing data in PHP! I heard that the title should be long! The textbox defined in HTML is as follows: Plain & lt; inputname = & quot; my_test & quot; value = & quot; 1 & quot; type = & quot; text & quot; maxlength = & quot; 3 & q encountered a strange problem when passing data in PHP! I heard that the title should be long!
The textbox defined in HTML is as follows: struct
When the form button is submitted, the background accepts the following: Accept
$ Num0 = (string) $ _ POST ["my_test"];
$ Num1 = (int) $ _ POST ["my_test"];
$ Num2 = intval ($ _ POST ["my_test"]);
$ Num3 = $ num0 * 1;
Echo $ num0;
Echo $ num1;
Echo $ num2;
Echo $ num3;
Print the following information after running:
1 0 0 0
Why is this the case? why is it changed to 0 by default when the force type is set to 1 ?????? Answer
------ Solution --------------------
1111
No problems have been found after testing.
------ Solution --------------------
I don't know if LZ encoding is a UTF-8. if it is possible, it may be related to BOM.
------ Solution --------------------
Send your complete code. this is wide enough.
------ Solution --------------------
I tried it with UTF-8, and it's all 1 ..
------ Solution --------------------
I tried, but I still didn't find any problems...
------ Solution --------------------
I have also encountered this problem for you! It is strange that when the value is 1, when you use intval () and (int) $ var to convert the variable type, 1 is 0! This is a strange problem! It may be related to encoding. at that time, the encoding was utf-8. I don't know if this problem will happen to gbk!
Please solve it !!!!!!!!!
------ Solution --------------------
If ($ _ GET ["type"]) {
I think the code behind you didn't pass type... and the output. $ num2 is not num2...
In addition, addslashes needs to filter strings. you give arrays...
If ($ _ GET ["type"]) {
$ Num1 = (int) $ _ POST ["my_test1"];
$ Num2 = (int) $ _ POST ["my_test2"];
Echo $ num1. "-". $ num2;
}
?>
There is no problem with this code. If this code is still incorrect, what is your php version?
------ Solution --------------------
C/C ++ code
If (! Get_magic_quotes_gpc () {addslashes ($ _ POST); addslashes ($ _ GET);} if ($ _ GET ["type"]) {$ num1 = (int) $ _ GET ["my_test1"]; $ num2 = (int) $ _ GET ["my_test2"]; echo $ num1 ."-". num2 ;}
------ Solution --------------------
There are many errors.
Encode the array X passed in;
A character is connected to a number, and the result must be a character. You can write in the code:
$ N1 = 3;
$ N2 = 5;
Echo $ n1. '_'. $ n2;
The result is 3_5;
For your type conversion problem, I guess it is an HTTP problem. I have seen it in the past. We recommend that you run the var_dump command for each converted type.