After a long period of work accumulation, summed up some of the PHP application skills, here to share to everyone. PHP (hypertext Preprocessor) is a kind of HTML embedded language, is also the most popular web programming language. It supports a variety of back-end databases, with almost all of the current database systems covered. At the same time it contains the general language of mathematical operations, time processing, file system, string processing, travel processing and other functions, plus it is a free system, making cost and benefit ratio, almost equal to infinity.
1, PHP application skills to determine whether a function is supported
Since in PHP we can flexibly use to increase or decrease the PHP support module, so sometimes we use PHP before, always first determine whether a module is loaded, for example, to see if the GD graphics module is supported, you can use the following code:
- if (!function_exists (' imagecreate ')) {
- Die (' This host does not currently support GD graphics module ');
- }
- ?>
Similarly, we can use similar code to test whether modules such as MSSQL,OCI are supported.
2, PHP application skills in the string to change the URL into a hyperlink
When submitting a form in a Web page, it's often a good thing to have URLs in the text of the submission, such as a profile, or automatically turn it into a hyperlink when it's displayed, just like when you edit a document with Word. The following code is a good implementation of its function.
- $ string = "Connect Sadie http://www.ccidnet.com Site" ;
- Note: A space or carriage return is required after the connection.
- $ string = Eregi_replace ("HTTP//([^, rn]*)", " href=\0 tarrget=_blank >\0 ", $string);
- $ string = Eregi_replace ("ftp://([^, rn]*)", " href=\0 target=_blank >\0 ", $string);
- Print $string;
- ?>
3, PHP application skills in PHP processing multiple check boxes with the same name
If there is more than one check box with the same name in a form, there is only one value when committing to PHP, not a comma-delimited value like ASP. The workaround is to use the array. Add the name of the check box followed by [], for example:Switch。 This way, PHP will get an array called pp. In the submitted form, Count (PP) is used to determine the number of arrays, and then the array is processed separately. The same applies to the multi-select problem of the dropdown box.
4, PHP application techniques using static implementation of the table color interlaced display
We use PHP to query the data from the database, and output the results to the browser, if the result has a lot of rows, the table bgcolor (background color) If all is monochrome, the viewer will feel uncomfortable. So what do you do to make the table rows different colors? Take a look at the following code:
- function GetColor ()
- {
- static $colorvalue;//define a static variable
- if ($colorvalue= = "#eeeeee")
- $ ColorValue = "#F5F5F5" ;
- Else $ ColorValue = "#eeeeee" ;
- return ($colorvalue);
- }
- print ("border=1>n");//output 10 lines below
- For ($i=0; $i< ; $i + +)
- {
- $ Bcolor = GetColor ();//change background color
- print (" bgcolor= $bcolor >n");
- Print (" $i n");
- Print ("");
- }
- Print (" n");
- ?>
Description: A static variable is defined in this program $colorvalue meaning that after the function call ends, this variable $colorvalue also retains the value and does not disappear. When you call the GetColor () function again, the value of the variable $colorvalue is the value $colorvalue at the end of the last function call.
5, in PHP to avoid repeated reference method
As you know, in C, we can define a macro name with a # define, by checking whether the macro name is defined to determine whether the header file is referenced. There are similar problems in PHP, such as: A refers to B,c, b refers to C, and if no action is taken, C is referenced 2 times. This can lead to some strange problems. Workaround: Define a global variable and resolve the problem by checking that the variable is defined. The approach is simple, similar to C. Just this global variable I recommend using [' User_packages '] [' headfilename '] naming rules.
- if (!empty ($GLOBALS [' foodtails '] [' globaldefine ']) return;
- $GLOBALS [' foodtails '] [' globaldefine '] = true;
- Class Foodtails {...
- };
- ?>
In addition, require_once "headfiles.php" is used as much as possible in the main program; To avoid duplicate references.
http://www.bkjia.com/PHPjc/446510.html www.bkjia.com true http://www.bkjia.com/PHPjc/446510.html techarticle after a long period of work accumulation, summed up some of the PHP application skills, here to share to everyone. PHP (hypertext Preprocessor) is a kind of HTML embedded language, it is now more popular ...