Common PHP function code snippets that can be used directly (21 ~ 25)-php Tutorial

Source: Internet
Author: User
Common PHP function code snippets that can be used directly (21 ~ 25) Source: jquery tutorial? -? Www. jq-school.comShow.aspx? PHP: common PHP function code snippets that can be used directly by HypertextPre (21 ~ 25)

Source: jquery tutorial? -? Http://www.jq-school.com/Show.aspx? Id = 330

?

Initially thought to collectPHPThe skills may be difficult. now I have collected 25 more without knowing it. In fact, PHP is the abbreviation of Personal Home Page, which has been officially renamed as "PHP: Hypertext Preprocessor ", note that it is not the abbreviation of "Hypertext Preprocessor". This method of putting the name into the definition is called recursive abbreviation.

?

PHPFounded in 1994 by Rasmus Lerdorf, Rasmus Lerdorf is a simple program written in Perl to maintain personal webpages. These tools are used to show Rasmus Lerdorf's resume and Count Web traffic.

?

Later, I re-wrote the program in C language, including accessing the database. he integrated these programs with some form interpreters called PHP/FI, which can be connected to the database, generate a simple dynamic web page program. if the front-end users are learning to develop in the background, they can choose PHP.

?

Let's take a look at the previously shared code snippet.

1. common PHP function code snippets (1 ~ 5)

2. common PHP function code snippets (6 ~ 10)

3. common PHP function code snippets (11 ~ 15)

4. common PHP function code snippets (16 ~ 20)

Today is Article 5th, it mainly provides functions such as obtaining the complete url address of the current page, sorting by two-dimensional arrays, obtaining the time of all weeks in which a period of time is located, converting the character content to binary, and converting the binary content to the character content, that is, the 5 practical code snippets from 21st to 25.JqueryMembers of the school group andPHPDeveloped netizens improve development efficiency.


21. PHP functions to obtain the complete url of the current page

function get_url(){    $url = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';    $url .= $_SERVER['HTTP_HOST'];    $url .= isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : urlencode($_SERVER['PHP_SELF']) . '?' . urlencode($_SERVER['QUERY_STRING']);    return $url;}


22. PHP universal method for sorting two-dimensional arrays

function array_sort($arr,$keys,$type='asc'){ $keysvalue = $new_array = array();foreach ($arr as $k=>$v){$keysvalue[$k] = $v[$keys];}if($type == 'asc'){asort($keysvalue);}else{arsort($keysvalue);}reset($keysvalue);foreach ($keysvalue as $k=>$v){$new_array[$k] = $arr[$k];}return $new_array; } 


23. PHP implementation obtains the time of all weeks in a period of time

Function getWeek ($ startdate, $ enddate) {// The parameter cannot be blank if (! Empty ($ startdate )&&! Empty ($ enddate) {// Convert two dates to the timestamp $ startdate = strtotime ($ startdate); $ enddate = strtotime ($ enddate ); // The start date cannot be greater than the end date if ($ startdate <= $ enddate) {$ end_date = strtotime ("next Monday", $ enddate); if (date ("w ", $ startdate) = 1) {$ start_date = $ startdate;} else {$ start_date = strtotime ("last Monday", $ startdate );} // calculate the time difference between weeks $ countweek = ($ end_date-$ start_date)/(7*24*3600); for ($ I = 0; $ I <$ countweek; $ I ++) {$ sd = date ("Y-m-d", $ start_date); $ ed = strtotime ("+ 6 days", $ start_date ); $ eed = date ("Y-m-d", $ ed); $ arr [] = array ($ sd, $ eed ); $ start_date = strtotime ("+ 1 day", $ ed) ;}return $ arr ;}}}


24. PHP converts character content to binary
Function StrToBin ($ str ){

Function StrToBin ($ str) {// 1. list each character $ arr = preg_split ('/(?
 



25. PHP converts binary into character content
Function BinToStr ($ str ){

function BinToStr($str){    $arr = explode(' ', $str);    foreach($arr as &$v){        $v = pack("H".strlen(base_convert($v, 2, 16)), base_convert($v, 2, 16));    }    return join('', $arr);}

?


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.