Php combined with forms to implement some simple functions. example _ PHP-php Tutorial

Source: Internet
Author: User
I learned to write forms over the past two days. To be noted. Example 1 (POST submission form ):
The code is as follows:


<BR> Chunkify Form <BR>







The code is as follows:


<BR> Chunkify Word <BR>

$ Word = $ _ POST ['word'];
$ Number = $ _ POST ['Number'];
$ Chunks = ceil (strlen ($ word)/$ number );
Echo "The $ number-letter chunks of '$ word' are:
\ N ";
For ($ I = 0; $ I <$ chunks; $ I ++ ){
$ Chunk = substr ($ word, $ I * $ number, $ number );
Printf ("% d: % s
\ N ", $ I + 1, $ chunk );
}
?>



Html page.

Page processed by php after the form is submitted. In this example, I enter a word, and then give it a length, and divide the word into blocks of that length.

The POST method is used to submit a form.
Example 2 (single choice, GET accept form ):
The code is as follows:


If (array_key_exists ('s ', $ _ GET )){
$ Des = implode ('', $ _ GET ['Att ']);
Echo "You have a $ des personality .";
}
?>


Example 3 (multiple options, GET accept form ):

Note thatThe underline tells GET that you are transmitting an array, while the black part indicates that the selection box is changed to multiple selection boxes. The code is as follows: If (array_key_exists ('s ', $ _ GET )){$ Des = implode ('', $ _ GET ['Att ']);Echo "You have a $ des personality .";}?> Example 4 (check box checkbox): the same name = "att []" indicates that GET transmits an array, and checked indicates that this option is the initial default option. in the same example, you can also add selected = "selected" to the tag.Select multiple options by default. The code is as follows: If (array_key_exists ('s ', $ _ GET )){Echo"";Print_r ($ _ GET );Echo"";If (is_null ($ _ GET ['Att ']) exit;$ Des = implode ('', $ _ GET ['Att ']);Echo "You have a $ des personality .";}?> Example 5 (single answer): Note that the same option must have the same name The code is as follows: When you click a single-choice button, the button changes to the selected status, and all other buttons change to the unselected status. Example 6 (stick form) The code is as follows: $ F = $ _ POST ['FA '];?> If (! Is_null ($ f )){$ C = ($ F-32) * 5/9;Printf ("%. 2lf is %. 2lfC", $ f, $ c );}?> Are some simple form processing ~Knowledge make me stronger!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.