PHP Learning Notes (ii)

Source: Internet
Author: User

1, PHP switch is very special, support strings and other basic classes to get.

function Dump_array ($var) {switch (GetType ($var)) {case ' integer ': Case ' double ': Case ' string ': Echo $var; Break;case ' Array ': Echo ' <table border= ' 1 ' > ';d o{echo ' <tr><td align= ' left ' valign= ' top ' > '; echo key ($var); Echo ' </td><td> ';d ump_array ($var [Key ($var)]; Echo ' </td></tr> ';} while (Next ($var)), Echo ' </table> '; Break;default:echo ' unknow data type. '; Break;}}

  

2. Object-oriented

2.1 PHP support for objects is not complete, such as the inability to fully use polymorphism to execute a function in a overridden parent class.

2.2 PHP cannot have two references to the same object, and when a reference is assigned to the second variable, a copy of the image is copied, and the new reference points to the replica.

3, URL parameters should use the Rawurlcode () function to convert the encoding, otherwise prone to illegal values and cause a crash

With Rawurlcode encoding, the decoding process is automatic when it is received.

4, PHP and HTML mixed

in PHP, adding @ before a function call can force the output of the corresponding warning and error message.

The following is a mixed MySQL database connection page.

<?phprequire (' common.inc '); require (' Post_get_arr.inc ')? ><?phpif (Empty ($arr _request[' username '])) {$ Username = ' root0 ';} else{$username = $arr _request[' username ');} if (Empty ($arr _request[' password ')) {$password = ' 123456 ';} else{$password = $arr _request[' password ');} $id _link = @mysqli_connect (' localhost ', $username, $password), if (! $id _link) {affy_message ("the connection to the local D Atabase has failed. Pleaseenter a username and password so a connection can be made. "); ><!--Display A form to gather username and password info--><form action= "connect_db.php" method= "POST" &GT;&L T;table><tr><td>username</td><td><input type= "text" name= "Username" value= "root" ></td></tr><tr><td>password</td><td><input type= "Password" Name= " Password "&GT;&LT;/TD&GT;&LT;/TR&GT;&LT;TR&GT;&LT;TD colspan=" 2 "><input type=" Submit "value=" Connect to Database "></td></tr></table></form><?phP exit; }?><p> the Connect was successful!</p>

  

5. The code can be called at the top of the PHP call, and the Get and post parameters are uniformly placed in the array

<?php//post and get value$arr_request = Array (); $HTTP _get_vars = $_get; $HTTP _post_vars = $_post;if (count ($HTTP _get_ VARS) {(List ($key, $value) = each ($HTTP _get_vars)) {$arr _request[strtolower ($key)] = $value;}} if (count ($HTTP _post_vars)) {while (list ($key, $value) = each ($HTTP _post_vars)) {$arr _request[strtolower ($key)] = $ value;}}? >

  

PHP Learning Notes (ii)

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.