• <option id="g6wei"><source id="g6wei"></source></option>
    <fieldset id="g6wei"><dd id="g6wei"></dd></fieldset>
  • \n<\/p>?????????????????????????????????????????????????\n

    ????????????????? if (isset($_POST['submit'])) {<\/p>\n

    \/\/isset detects whether the variable is set, exists, or non-NULL. The return value is Boolean. If the variable exists, it returns true, otherwise it is false; combined with $_POST[\"submit\"], $_POST \/\/Receive method= through the form 'post' method passing value<\/p>\n

    ???????????????????? $num1 = $_POST['num1'];\/\/Get the value in the first input box through the name attribute in the input <\/p>\n

    ?????????????????????? $select = $_POST['select'];\/\/Same as above<\/p>\n

    ?????????????????????? $num2 = $_POST['num2'];\/\/Same as above<\/p>\n

    ???????? if (is_numeric($num1) && is_numeric($num2)) {<\/p>\n

    ??????????? \/\/is_numeric() \/\/Detect whether the variable is a number or a numeric string Return value, true, false Such as 100, ‘100’<\/p>\n

    <\/p>\n(SWITCH ($ Select) {\/\/ $ Select is the operator from the previous\n

    ??????????????????????????????? case '+':\/\/ According to the syntax of switch, if the value in case is equal to the value in the brackets of switch, then execute the sentence after case, if not, continue looking down <\/p>\n

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\n<\/p>???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\n

    ??????????????????????????? case '-': <\/p>\n

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<\/p>\n

    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\n<\/p>????????????????????????????? case '*':

    \n<\/p>?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? $result = $num1*$num2;

    \n<\/p>??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\n

    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? default:<\/p>\nU If ($ num2 == 0) {\/\/ Add a judgment, the division cannot be 0

    \n<\/p>????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? echo \"

    国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

    Home php教程 php手冊 A calculator based on a small program written in PHP basic language

    A calculator based on a small program written in PHP basic language

    Dec 05, 2016 pm 01:26 PM

    Calculator based on a small program written in PHP basic language

    Requirement: Enter numbers in the input box to perform addition, subtraction, multiplication and division operations (html+php)

    Thought:

    1 First, create an input box for inputting numbers and operators. Use the text attribute of input for numbers and the option attribute of sellct for operators

    2 Click the = sign in the input box to perform the corresponding operation,

    3 = This input box can be done using the submit of input. Just click the submit form and the content in the form will be sent to php

    4 Determine the operators obtained from html and perform corresponding operations

    5 After the operation is completed, the result must be returned to the form (that is, assigning a value to the form)

    Code

    Html code

    //Method represents the form submission method. In this case, post submission is selected. Action is the accepted page. If it is empty, it means submitting to the current page.

    ??????????????????????????????????????????

    ????????????????????

    ?????????????????????????????????????????????????

    ???????????????????????????????????????????

    ????????

    PHP code

    When the user clicks the submit button, the value will be passed through post. Now we need to accept the value in the form.

    Make a few judgments before clicking

    if (isset($_POST['submit'])) {

    //isset detects whether the variable is set, exists, or non-NULL. The return value is Boolean. If the variable exists, it returns true, otherwise it is false; combined with $_POST["submit"], $_POST //Receive method= through the form 'post' method passing value

    $num1 = $_POST['num1'];//Get the value in the first input box through the name attribute in the input

    ?????????????????????? $select = $_POST['select'];//Same as above

    ?????????????????????? $num2 = $_POST['num2'];//Same as above

    ???????? if (is_numeric($num1) && is_numeric($num2)) {

    ??????????? //

    is_numeric() //

    Detect whether the variable is a number or a numeric string

    Return value, true, false Such as 100, ‘100’

    (SWITCH ($ Select) {// $ Select is the operator from the previous

    ??????????????????????????????? case '+':// According to the syntax of switch, if the value in case is equal to the value in the brackets of switch, then execute the sentence after case, if not, continue looking down ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????? case '-':

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

    ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    ?????????????????????????????? case '*':

    ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? $result = $num1*$num2;

    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? default:

    U If ($ num2 == 0) {// Add a judgment, the division cannot be 0

    & Echo "& lt; script & gt; alert ('The division of the input is 0, please re -enter') & lt;/script & gt;"; } Else {

    ???????????????????????????????????????????????????????????????????????????????????????????????????

    ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

    ????????????????????????????????????????????????????????????????????????????????????????????

    ?????????????}

    ??????????????????}else{

    當(dāng) // Echo When the user enters not the number, it may be a string to give the user a prompt

    ?????????????????????????????????????????????????????????????????????????? echo "<script>alert('The input is not a number')</script>";

    $ Num1 = $ num2 = $ result = "" ""; // Clear the content of the form in the form

    ?????????????}

    }

    Screenshot of running results

    Screenshot when entering the correct number

    Click = after the number

    Indicates that the value is not passed to the form in html,

    Now let’s set the value of the form

    //Set the value of value to the num value after operation in php

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ~ ~ ~

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???????????????????????????????????????????????????????????????????????????????????????????????????????

    ??????????????????????????

    ???????????????????????????????????????????????

    ???????????????????

    ????????

    Run results

    The input box now has content when the user does not click the submit button, so the value in the input box should be set to empty when the user does not click the submit button

    Improve the coding, add an else{

    at the end of the php code

    $num1 =$num2 = $result = "";

    }

    Screenshot

    When clicking on other operations, the operator in the middle is always +, screenshot

    Code improvements

    in html

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

    ??????????????????????????????

    ????????????????????????????

    ???????????????????????????????????

    ????????????????????????????????????

    ???????????????????????????????????????????????????????????????????????????????????????????????????????

    ??????????????????????????

    ???????????????????????????????????????????????

    ?????????????

    ??????

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)