PHP Small Summary

Source: Internet
Author: User
Tags set cookie

<?PHP// 1.php Base syntax //Output statement echo print Print_r var_dump ()//2.php is a weakly typed language //cast type: (type) variable settype (variable, type)/ /3. Variable definitions $a= 5;//variable variable: $b = "a";   $ $b = 10;//Determines the variable type gettype (variable), gets the variable type Is_ type () Is_int (), determines whether the variable is the type//judgment variable is empty: empty (); Isset ()//delete variable: unset (); //4. How strings are defined $str= "Hello";//can parse escape characters and variables$str= ' Hello ';//escape characters and variables cannot be parsed$str= <<<Ahelloa;//don't worry about single and double quotes //5. Operator expressions (+-*/+ +--= etc.)//6. Statement //branch: If switch...case//loop: for foreach whi Le do...while//7. Functions //Four elements: return type, function name, parameter list, function body//definition of function in PHPfunctionShow ()//Normal{}functionShow$a)//there's a return.{}functionShow ()//has the default{    return $a;}functionShow$a=5)//has the default{}functionShow ()//variable-parameter{    Func_get_args();}//8. Commonly used functionsRandom number: rand (); Rand (0,10); random number between 0~10/datetime: Time (), can get current datetime timestamp//date (formatted string, timestamp); format datetime, y-m-d year-month-day h-i-s hour-minute-second Uppercase H is a 24-hour lowercase h is a 12-hour//strtotame (a string representing an event); Converts a string to a timestamp//9. OtherError suppressor @//Exit Program: Exit (); Die ("error message");//************************************************************************************************ ********//Two, the common method of string//1. Take the length of the string:Strlen ();//2. Splitting a string:Explode ();//3. Merging strings:Implode ();//4. Intercepting a string:SUBSTR ();//5. Replacement string:Str_replace (); Find replacement Substr_replace (); Specify location substitution//6. Go to space:Trim ();//7. Turn Capital:Strtoupper ();//8. Turn lowercase:Strtolower ();//9. Split by Length:Str_split ();//************************************************************************************************ Third, regular expression//1. Delimiter:/   ///2. Start of match:^ Match End $//3.\d any number \a an invisible character \w any number or word character + The preceding expression appears at least once {0,2} The expression preceded by at least 0 occurrences of the maximum occurrence of 2 times//[0,1,2] matches any character [0-9] matches the number between 0-9 [A- Z] matches a A-Z word character ()--priority |--or//4. Splitting a string:Preg_split ();//5. Replacement string:Preg_replace ();//6. Match the data that appears in the string (to satisfy the regular):Preg_match (); Preg_match_all ();//******************************************************************************************* Four, array//1. Array classification:By dimension: one-dimensional arrays and multidimensional arrays//based on index: indexed arrays and associative arrays//2. Array definitions$attr=Array();//Common definition methods$attr[] = 5;//Assignment definition//Definition index array: $attr = Array (1,2,3,4);//define associative array: $attr = Array ("Key" = "value");    //3. Value //indexed array: $attr [0]; Associative array value: $attr ["Key"]; //4. Iterating through an array://for loops, only traversing indexed arrays for($i= 0;$i<Count($attr);$i++){    $attr[$i];}//foreach traversal to facilitate indexed arrays and associative arraysforeach($attr  as $v){    $v;}//Each () and List () methods combineEach (): Returns the key and value of the current element inside the array, returning an array of form//list (): Assigns the value of the right array to a list of variables ($a, $b)//Pointer traversalTakes the value of the element pointed to by the current pointer: present ();    Key:key () of the element to which the current pointer is pointing;    Point the pointer to the next element: Next ();    Point the pointer to the previous element: prev ();    Resets the pointer: Reset (); Point the pointer to the last element: End ();//5. Common functions for arraysTake the array length: count ();//To add elements to an array: Array_push ();//Determine if an array contains an element: In_array ();//merge array: Array_merge ();//repeat: Array_unique (); /delete array element: unset ();//re-index: array_values ();//Flip array: Array_reverse ();//array element ordering: Array_multisort ();//******************** ***************************************************************************************//Five, object oriented OOP//1. Classes and ObjectsClasses are abstracted from many objects, and objects are instantiated from classes.//2. Definition of class:Class ren{}//Includes member variable member method constructor destructor __get () method __set () method __tostring () method __clone () method//3. Access modifiers:Public private privately owned protected protected//4. Three major featuresEncapsulation: Purpose approach//Inheritance: Conceptual feature function or method rewrite//polymorphism: Conceptual condition//5. Static:Statically static members belong to the class, and the ordinary members are the objects that belong to the//6. Abstract class:Abstract class cannot be instantiated, generally used as parent//interface interface can define methods but do not write function body//7. Cloning objects:Clone//8. Constructors:__construct () Special Execution Time Special//9. Loading Classes    include(""); include""; require(""); require""; require_once(""); require_once"";//Auto Load Class __autoload ();//10. Single-row modeControl class can only generate one object//11. Factory mode//************************************************************************************************************
//VI, data access//1.mysqli:$db = new mysqli (server, username, password, database);//mysqli_connect_error ();//Determine if the connection is successful//$result = $db->query (SQL statement);//$result Fetch_row ();//2.pdo$pdo = new PDO (DNS, username, password);//$stm = $PDO->prepare (SQL statement); Put this SQL statement on the server to wait for execution//$stm->excute ();//$stm->fetch_row ();//Can be used in SQL statements? To make a placeholder: a string placeholder//************************************************************************************************************
//Seven, Jquery Ajax //1. Selector--$ ()Select $ ("#id") based on the ID to return a jquery object, take the DOM object from inside the jquery object to index 0[0]//select $ (". Class")////According to the attribute select $ ("[name=a]")// Signature Select $ ("div")//2. Operating contentManipulate non-form content: Text (); HTML code HTML ();//Manipulating form elements: Val ();//3. Action PropertiesAdd settings Property: attr (property name, property value);//Get Property: attr (attribute name);//Remove attribute: Removeattr (attribute name);//4. Operation StyleGet style: CSS (style name);//Add Setting Style: CSS (style name, style value);//5. Events$ ("#id"). Event name (function () {}),//$ ("#id"). Bind (event name, function () {}), bind event//$ ("#id"). Unbind (event name); Remove Event//6.ajaxAsync Asynchronous processing//url: Called Processing page//data: Data JSON format passed//type: How data is passed post or Get//datatype: Return data type text/json/xml//success: callback function// Error: A method that executes when an error is invoked//7.jsonFormat: {Key:value}//8.xml DocumentationFormat: Must have a root, and start must have end, case sensitive, tag name can be customized, you can add attributes//9. Session Control//session Features:
Stored on the server, there is a default expiration time, each user saves one copy, can store any type of data//must be turned on to use Session_Start (); must be written in the first line//$_session["UID"] = "List"; Pros: Security drawbacks: Seizing resources//cookiestored in the client by default is not the time period, each user saves one copy, only the string//setcookie (name, value), set cookie//$_cookie["UID"; Read COOKIE Advantage: No resource disadvantage: unsafe//*********** **************************************************************************************************
//Nine, file//1. File UploadDo file Upload form enctype//$_files Array read file information//control upload file format and size//build storage path (processing file name) to file name to create Folder//Determine whether the file exists//upload save Move_u Ploaded_file ();//transcoding format iconv (original code, target encoding, string);//2. File OperationsFile type: filetype () is_file () Is_dir ()//path:./current path. /parent Path/downlevel path//Traverse directory: Glob (); Returns all files in this directory, is a collection. New directory: mkdir (); Create a new directory//delete directory: RmDir ();//Mobile Directory: rename ();//New file: Touch ();//delete file: Unlink ();//Copy file: Copy ();//Get File Contents: FI Le_get_contents ();//write content: File_put_contents ();//File resources:Open File resource: fopen ();//Close File resource: fclose ();//Read file contents: fgetc (); read a fgets (); Read a row of fread (); Fwrite ();

PHP Small Summary

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.