PHP is currently the most widely used web-based programming language, driving millions of web sites, including some large sites such as Facebook. This collection of 21 practical and convenient snippets of PHP code is helpful for each type of PHP
This example describes how PHP uses the Strstr () function to get all the characters after the specified string. Share to everyone for your reference, specific as follows:
The Strstr () function of PHP searches for the first occurrence of a string
This article describes the STRNATCMP () function "Natural sorting algorithm" in PHP for string comparison usage. Share to everyone for your reference, specific as follows:
The strnatcmp () function in PHP uses the "natural" algorithm to compare two
When the content of the article is relatively long, in order to better meet the user experience, we will page the content of the display processing, and general paging is the post in the background when the submission of the content generated more
1. Get the remote file size and information function
function GetFileSize ($url) {
$url = Parse_url ($url);
if ($fp = @fsockopen ($url [' Host '],empty ($url [' Port ']): $url [' Port '], $error)] {
fputs ($fp, "get". Empty ($url [' path '
This example analyzes the PHP bubble sort and fast sort algorithm. Share to everyone for your reference, specific as follows:
$a =array (' 3 ', ' 8 ', ' 1 ', ' 4 ', ' 11 ', ' 7 ');
Print_r ($a);
$len = count ($a); From small to large for ($i =1
We all know that in JS string intercept characters have functions substr and substring, that PHP, PHP is not directly available substring functions, but there are substr functions.Do not believe that you can test. The following is the correct code.
function is very simple, there are comments in the code, directly to everyone on the code
Copy Code code as follows:
/**
* Upload pictures to generate thumbnails
*
* Need support for GD2 library
*
* Initialization requires
Date--Format a local time/date
Gmdate-Formats a GMT/UTC date/time and returns Greenwich Standard (GMT).
For example, the time zone we're in is +8, so the server should return the following script:
Current time assumption is 2007-03-14 12:15:27
1. Sys_getloadavg ()
SYS_GETLOADAVT () can obtain the system load condition. The function returns an array of three elements, each representing the average load of the system in the past 1, 5, and 15 minutes, respectively.
Rather than letting the
This example describes how PHP obtains the client browser name and version. Share to everyone for your reference, specific as follows:
See a function in Ecshop get_user_browser () to get the name and version of the browser. Although the information
Core code
starttime=this->getmicrotime ();
}
function display ()//Displays the time of the page execution
{
this->stoptime=this->getmicrotime ();
this->spendtime=this->stoptime-this->starttime;
Return round (this->spendtime,10);
}
/*
ISSET ();--suitable for detecting the existence of this parameter.
Definition and scope: used to test whether a variable has a value (including 0,false, or an empty string, but not null), that is, "http://localhost/?fo=" can also be detected and
There are two submit buttons in the form, to achieve when clicking on the different submit button, two different processing process, where the implementation of the form multiple Button submission action method to share with you.
Using PHP to judge,
The following code implements the ability to include different files according to the file name of the browser's address bar parameter.
Copy Code code as follows:
$file _name = $_get["filename"]; Get the current file name
Include ("
1.?? Operator (NULL merge operator)put this in the first place because I think it's very useful. Usage:
$a = $_get[' A ']?? 1;
It is equivalent to:
We know that ternary operators can be used in this way:
$a?: 1
This article to introduce you to a good need to login PHP file Upload management system, the function of a simple need to know students can refer to. Code as follows
Please login Enter Password: Authentication characters: form>
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