PHP creates a calculator and solves some problems.
Source: Internet
Author: User
PHP has made a calculator. if something goes wrong, solve it! Here is the processing code for making 0 inputs: ========================================================== ==================================== if ($ _ POST ['num0']) {& nbsp; $ num PHP creates a calculator and solves some problems!
Here is the processing code for making 0 inputs:
If ($ _ POST ['num0']) {
$ Num = $ _ POST ['num0'];
If (is_dir ('txt ')){
$ Open = fopen ("txt/caculator.txt", "r + ");
If (is_file ("txt/caculator.txt ")){
$ A = file_get_contents ("txt/caculator.txt ");
$ E = (int) $;
$ B = $ e. "0 ";
Echo $ B;
File_put_contents ("txt/caculator.txt", $ B );
Fclose ($ open );
}
}
}
========================================================== ======================================
This is the form:
========================================================== ======================================
========================================================== ======================================
All code is on the second floor.
Create a folder txt under localhostand then caculator.txt.
Caculator2.txt; caculator3.txt; display the numbers in a single-click dialog box and store them in caculator.txt,
Then, click the number button to enter the second operation number and
The number is stored in caculator.txt. when a single number is equal to the number, the operators saved in caculator3.txt are judged and then
Corresponding operation.
All other functions can be implemented. when the input is 0, the program will not store 0 in the file, resulting in the failure to implement the input 0,
I don't know any questions. please answer them. Preliminary estimation is about the data type... Php file storage
------ Solution --------------------
Your problem is:
If ($ _ POST ['num0']) {
Because $ _ POST ['num0'] is equal to 0, the constant condition is invalid. This branch will not enter!
Change
If ($ _ POST ['num0'] = '0 '){
Your program design is unreasonable and requires significant adjustments.
Improper use of file operation functions
Since file_get_contents and file_put_contents are used to read and write files, fopen and fclose are not required.
File_put_contents has a FILE_APPEND parameter that can be used to append content to a file without reading it and then manually appending it.
If necessary, you can use the adjusted code for your reference.
------ Solution --------------------
Using AJAX, and then dynamic PHP compilation, we can put a lot of companies into computing.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service