PHP face Test

Source: Internet
Author: User
Tags explode

echo, print, Print_r, var_dump differences
    • Echo and print are language structures that are not functions and can only print out strings and int
    • int print (string $arg]) since it is a language result, there is no need to add brackets (print) at once
    • Print_r has only two parameters, the second parameter is used to determine whether to output (TRUE capture), can print out the structure, and has a return value, remember,print_r () will move the pointer of the array to the last side. Use Reset () to get the pointer back to the beginning.
    • Var_dump no return value, can print out structure
Strtotime (), the use of functions
Echo Date("Y-m-d h:i:s",Strtotime("Now")), "\ n";Echo Date("Y-m-d h:i:s",Strtotime("September"), "\ n";Echo Date("Y-m-d h:i:s",Strtotime("+1 Day"), "\ n";Echo Date("Y-m-d h:i:s",Strtotime("+1 Week"), "\ n";Echo Date("Y-m-d h:i:s",Strtotime("+1 Week 2 days 4 hours 2 Seconds"), "\ n";Echo Date("Y-m-d h:i:s",Strtotime("Next Thursday"), "\ n";Echo Date("Y-m-d h:i:s",Strtotime("Last Monday"), "\ n";
Which tools to use for version control
Svn,git,cvs

Implementing string flipping

$str= "Wwweeerr";$len=strlen($str);$rev _str= ' '; for($i=$len;$i>= 0;$i--) {    $rev _str.=$str[$i];}Echo Strrev($str), "<br>";Echo $rev _str;$str _c= "Hello";$len _c= Mb_strlen ($str _c, ' GB2312 ');$rev _c= ' '; for($i=$len _c;$i>= 0;$i--) {    $rev _c. = Mb_substr ($str _c,$i, 1, "GB2312")
);} Echo  $rev _c;

Set session life cycle: Session_set_cookie_params

Require require_once include, include_once difference

Include produces a warning, while require produces a direct error interrupt

Require, include to load before running

Require_once, include_once If the file is included, it will not contain the file

Efficiency aspects

Include_once (), require_once (), compared to include (), require (), is less efficient because they have to at least determine if the file is already contained. This issue has been greatly improved in the PHP5 version, but there is still a difference in efficiency.

There are two important differences between require and include. First, the file will be included in the script that appears require, regardless of the location of the require. For example, even if the require is placed in an if statement that evaluates to FALSE, the specified file will still be included. The include can be placed in a conditional statement.

In PHP, Heredoc is a special string whose end flag must be the same as the start flag
$dd = <<<dddd;
MVC Awareness

M:model (model), dealing with data (database)

V:view (view) display data

C:controller (Controller) handles business logic, which is the transfer of data

The difference between a value in PHP and a pass-through reference. When to pass the value, when to pass the reference

Reference value: Use &, change the value of the reference value in the function scope, will cause the outside to be worth changing

Transfer value: Equivalent to copy, within the scope of the function of the change in value, will not cause the outside to be worth changing

Pros and Cons: If it is a large string and object to pass value, will consume a lot of memory, affect performance, so this operation is prudent, if it is a reference value, it is passed an address, has no effect on performance.

Error_reporting What this function does in PHP: report the error level.

Mailbox regular match:/([a-z\d]+[\._-]) @ ([\a-z\.\d_-]+) \. ([a-z]+)

How to get the current execution script path, including the obtained parameters:

__file__ Get Path

$ARGC--Get the number of parameters

$ARGV--Get the list of parameters

What is the difference between foo () and @foo (): @ means ignore warning

Permissions control modifier in PHP: Public private protected

The function that gets the total number of query result sets is: Mysql_num_row ()

$arr = Array (' James ', ' Tom ', ' Symfony '); Please print out the value of the first element
$arr Array (' James ', ' Tom ', ' Symfony '); Print_r ($arr[0]);
//Do not move the pointer.  print_r(current ($arr)); // /will move the pointer Print_r (array_shift($arr));

Write a function that removes the file extension from a standard URL as efficiently as possible

For example: http://www.sina.com.cn/abc/de/fg.php?id=1 need to remove PHP or. php

$url= "Http://www.sina.com.cn/abc/de/fg.php?id=1";$pathinfo=PathInfo($url);Var_dump($pathinfo);$url _array=Explode(‘?‘,$pathinfo[' extension ']);Echo $url _array[0]. " <br> ";//PHP$parse _url=Parse_url($url);Echo substr(basename($parse _url[' Path ']),Strrpos(basename($parse _url[' Path ']), '. ');//. php//regular Match \w is [0-9a-za-z_] contains letters, numbers, and underscores$result=Preg_match("/[\w-]+ (. php) [\w-=?] +/",$url,$matched);Echo  $matched[1];//you can also directly match$result _again=Preg_match("/[\w\/-]+ (. php) [\w\/-=?] +/",$url,$matched);Echo  $matched[1];
Calculate Relative Road strength
//calculates the relative road strength B line for a$a= '/a/b/c/q/d/e.php ';$b= '/a/b/12/34/c.php ';$array _a=Explode(‘/‘,$a);$array _b=Explode(‘/‘,$b);$len _b=Count($array _b); for($i= 0;$i<$len _b;$i++) {    if($array _b[$i] !=$array _a[$i]){        $dismatchlen=Count($array _a)-$i; $rel _path=Array_slice($array _b,$i);  Break; }}$relative _path=str_repeat(‘.. /‘,$dismatchlen).implode(‘/‘,$rel _path);Echo  $relative _path;
Traverse all files and subfolders under a folder.
//traverse all files and subfolders under a folder$path=dirname(__file__);functionEach_dir ($path){    //It 's best to do a security check before traversing    if(Is_dir($path)) {        //Open Directory handle        $re=Opendir($path); //reading entries from the directory handle         while(($file=Readdir($re)) !==false) {            if($file= = '. ' | |$file== "..") {                Echo $file. "<br/>"; //make the Next loop                Continue; }            $r _path=$path. ‘/‘ .$file; //if the file output            if(Is_file($r _path)) {                Echo $r _path. "<br/>"; Continue; }            //Recursive invocation            if(Is_dir($r _path) {each_file ($r _path); }        }        //Close Resource        Closedir($re); }}each_dir ($path);

PHP face Test

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.