PHP and html_php Tutorials

Source: Internet
Author: User
PHP and HTML
PHP and HTML can interoperate: PHP generates HTML, and HTML can pass information to PHP. 1. How do I encode/decode when I use a form/url to pass a value? 2. I'm using tag, but $foo. x and $foo. Y variables are not available. Where are they? 3. How do I create HTML Array? 4. How do I get all the result values from a multi-box?
1. How do I encode/decode when I use a form/url to pass a value?
In a few stages, coding is very important. Suppose you have a string variable $data that contains some of the characters that you want to pass in an unencrypted way, following the encoding of the stage:

HTML interpretation. In order to represent any string, you must enclose it in double quotes, and it is the HTML special character to use htmlspecialchars notation.
Url:url is made up of several parts. You want your data to be considered part of the URL, and you must encode it with UrlEncode ().


Example 52-1. Hidden HTML form Elements \ n ";? >
Note: It is not possible to use UrlEncode () $data because the UrlEncode () data is the responsibility of the browser. Most browsers can handle such data correctly. Whichever method (GET POST) is used. You can consider only GET requests, because POST requests are usually hidden.
Example 52-2. User edits data \ n "; echo Htmlspecialchars ($data). " \ n "; echo "";? >
Note: The data displayed in the browser window is decoded to be readable because the browser interprets the HTML tags.
Once committed, the browser will encode the data as it is transmitted, regardless of the get or POST, and PHP will decode it. Everything is done automatically and you don't have to do anything.
Example 52-3. In the URL string
Note: You are actually writing a GET request yourself, so it is essential to encode it with UrlEncode ().
Note: You need to htmlspecialchars () the entire URL string because the URL string is part of the Html-property. In this case, the browser first-htmlspecialchars () This value and then sends out the URL. PHP will recognize this URL string because you coded it with urlencoded ().
You will find that & is replaced with &amp in the URL string;. Although you do not encode most browsers will help you do, but not all can. So even if you're writing a static URL, you need to use Htmlspecialchars () to encode the URL.

2. I'm using tag, but $foo. x and $foo. Y variables are not available. Where are they?
In submitting a form, you might use an image control instead of using the standard submit button: When a user points to a place on the image control, the form is submitted to the server and has two additional variables: foo.x and FOO.Y.
Because $foo. x and $foo. Y are invalid variable names in PHP, so they are automatically converted to $foo_x and $foo _y. In other words, the dots are replaced with underscores.
3. How do I create HTMLArray?
In order for your form results to be sent as an array to the PHP script, you can give , Or The <textarea>element is named as follows:</textarea> Note that the brackets after the element name cannot be saved, that is, it makes the result an array. You can arrange them into different arrays by the name of the element: The above code produces two arrays, MyArray and Myotherarray, sent to PHP. Of course, you can also indicate a key value for your array: The Anotherarray array will hold subscript 0, 1, email and phone.

Note: It is optional to indicate the subscript value in the element name. If you do not indicate, the array will be filled in the order in which the elements appear in the form. As in our first example, the array subscripts are: 0, 1, 2 and 3, respectively.

See Array function and PHP external variables.
4. How do I get all the result values from a multi-box?
The multi-box in HTML is used to let the user select multiple values from the list. These values are then sent to the form's processing script. The problem is that they all have the same variable name. For example: Each selected item is then passed to the processing script: Var=option1var=option2var=option3 Each value overrides the value of the previous item. $var workaround is to use the PHP "table unit prime number" attribute. Here's the following:PHP treats $var as an array. Each selected item is assigned to an array cell. The first item is $var[0], the next item is $var [1], and so on. The count () function can be used to determine how many selections are in an array and, if necessary, to sort the arrays with the sort () function.
If you are using JavaScript, you may get an error using the element name reference directly. You should use its numeric index, or put the variable name inside a single quotation mark. For example: variable = documents.forms[0].elements[' var[] '];

http://www.bkjia.com/PHPjc/314345.html www.bkjia.com true http://www.bkjia.com/PHPjc/314345.html techarticle PHP and HTML PHP and HTML can interoperate: PHP can generate HTML, and HTML will pass information to PHP. 1. How do I encode/decode when I use a form/url to pass a value? 2. I'm using INP ...

  • 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.