: This article mainly introduces php learning 01. if you are interested in the PHP Tutorial, you can refer to it.
ObjectThis method * _ clone () is called during cloning. the default parameter $ this, $ that, $ this isObject, $ That is the originalObject* _ Construct constructor * _ destruct destructor * _ sleep (); whenObject* _ Wakeup () is called before serialization. when * _ autoload (included class name) is called before deserialization, when a class name method is called, if the class is not included, an error is returned. when this function is defined, the function is called to dynamically load the class file _ toString ().ObjectAn error is reported. if this method is defined, call this method **/class A {private $ name; private $ age; public function _ construct ($ name, $ age) {$ this-> name = $ name; $ this-> age = $ age;} public function _ set ($ name, $ value) {$ this-> $ name = $ value;} public function _ get ($ name) {if ($ name = 'fuck') return "fuck! "; If (isset ($ this-> $ name) {return $ this-> name;} else {return NULL ;}} public function _ call ($ name, $ args) {echo $ name, "Mothod does not exist"; var_dump ($ args);} public static function _ callStatic ($ name, $ value) {echo"Static method$ Name does not exist ";} public function _ clone () {$ this-> name =" I am cloned ";} public function _ sleep () {// echo "serialized"; return array (name) ;}// regenerateObjectCall public function _ wakeup () {$ this-> name = "Zhangsan"; $ this-> age = 234;} public function _ toString () {return "A" ;}}// $ a = new A ("zhang san", 22); // echo $ a-> name; // $ a-> name = "James"; // echo $ a-> name; // $ a-> get ("xue", 3, "sf "); // $ a1 = clone $ a; // echo $ a-> name ,"
", $ A1-> name; // $ p_str = serialize ($ a); // echo $ p_str; // $ a2 = unserialize ($ p_str ); // var_dump ($ a2); // function _ autoload ($ classname ){//Include$ Classname. ". php "; //} // echo $ a2-> fuck; // A: ha ();/** 1. difference between echo and print * echo is a statement, not a function. multiple values can be output without parentheses. no return value is returned. arrays andObjectOnly simple types can be output, such as int and string * print. it is a statement and is not a function. no parentheses are required. only one value can be output, with a return value of 1. arrays andObjectOnly simple types such as int and string * 2 can be output. print_r () and var_dump () * print_r () are functions that can output compound and simple types, such as int float, string, array object.ObjectWhen the * Array is output, it is represented as Array () * var_dump (). It is a function. the content, type, length, and simple type of the output variable can be output, composite type, often used for debugging * 3. printf is a function, similar to the C language, formatting string output * 4. sprintf function, similar to the C language, returns a formatted string without outputting ** // print_r (3.55); // $ arr = array ("xue ", 3); // print_r ($ arr); // var_dump ($ arr); // $ nb = sprintf ("% s is a % d hanging", "haha ", 3); // echo $ nb;/** method of obtaining file content * 1. file_get_contents (); ** // $ txt = file_get_contents('data.txt '); // echo $ txt; // $ file = fopen ("dat A.txt "," r "); // while (! Feof ($ file) {// $ line = fgets ($ file); // echo $ line; //} // while (! Feof ($ file) {// $ char = fgetc ($ file); // echo $ char; //}/** strlen () he mb_strlen difference * both functions evaluate the length of a string * only obtain the number of bytes occupied by the string in strlen and cannot properly process the Chinese character * when it is GB2313 encoded, A Chinese character occupies 2, when the UTF-8 encoding, a Chinese character occupies 3 * mb_strlen () can correctly process Chinese characters, the second parameter is the encoding type, the default is UTF-8, the default value is the internal PHP encoding. you can use mb_internal_encoding () to check that * mb_strlen () is not the core function of php. you need to load the extension library for use in php. extension = "php_mb_string.dll" * // $ str = "Daiyu 123f"; // echo strlen ($ str); // output 10 // echo mb_strlen ($ str, 'utf-8'); // output 6 // echo mb_internal_encoding (); // output ISO-8859-1 /// ** php array function * array key name and value * 1. is_array () determines whether it is an array. if it is TRUE, it returns TRUE, not false, similar to is_int (); is_float (); * 2. array explode (string $ delimiter, string $ string [, int $ limit]) This function splits strings into arrays * 3. string implode (string $ glue, array $ pieces) splits the array into a string * 4. array_values () returns all values of the array. create a number for it.Index* 5. array array_keys (array $ input [, mixed $ search_value = NULL [, bool $ strict = false]) * 6. array_key_exists () retrieves the specified key name orIndexReturns true if it is in the array. otherwise, returns false * 7. array_flip () exchanges the key names and values of the array. if the same value exists, the last key value prevails * 8. array_search () searches for a given value in the array. if a given value exists, the corresponding key name is returned. otherwise, FALSE * 9 is returned. returns true if a value exists in the array. If no value exists, returns FALSE * 10 if no value exists. isset ($ arr ['apple'] checks whether the specified key name exists in the specified array. If yes, true is returned, otherwise, false * array internal pointer * current ($ arr) is returned. the current unit pos ($ arr) in the array is returned. the current unit key ($ arr) in the array is returned ); returns the key name prev ($ arr) of the current unit in the array; returns the internal pointer in the array to one next ($ arr ); move the internal pointer in the array forward an end ($ arr); point the internal pointer in the array to the last unit reset ($ arr; The internal pointer in the group points to the first unit * each ($ arr); returns the key name and value of the current pointer unit of the array, in the form of a new array, and the pointer of the current array moves one step forward, if the last unit of the array is reached, the key-value pair is returned as an array of four units. The key name is>, key, and value. Unit 0 and key contain the key name of the array unit, and 1 and value contain data. * List ($ key, $ value); is a language structure that obtains the key name and value of the current element of the array and assigns a value to the variable, list can only be used without a key nameIndex* Convert the array ** between the array and the variable * extract () import the variable from the array to the current symbol table * check whether each key name can be used as a valid variable name, check the conflict with the existing variable names in the symbol table. * Compact () changes the variable to * array segment and fill * array_slice takes out a segment * array_slice ($ array, int offset, [int length, false | true]) in the array. * if the offset is negative, the number starts from the end of the array * if the length is negative, the sequence is terminated so far from the end of the array * array array_splice (array & $ input, int $ offset [, int $ length = 0 [, mixed $ replacement]) * deletes a segment of an array. based on the offset and length, replacement can be used to replace the unit to be deleted, the number of replicas is the same as the number of replicas. if it is an array, the key name * is not retained, only the value is replaced, or it can be a string. If no cell is deleted, then the replaced variable will be inserted to the offset location ** split multiple arrays * array_chunk (array, size, [true | false]) * split an array into multiple arrays. the element quantity of each array is size. if the size is smaller than 1, an error is returned. the element of the last array may be smaller than size. the default value is false, will discard the original arrayIndexOr key name * re-create a number starting from 0IndexIf it is true, the original key name orIndex** Array filling * array_pad (array, length, value); * fill the array with value to the length. * If the length is less than or equal to the length of the array, if length is negative, the array and stack * array_push (array, value,) are left Filled. * One or more values are pushed to the array stack, returns the number of elements in this array * array_pop (array); * returns the top element of an array stack. If the array is empty or not an array, returns NULL ** array and line-up * array_shift (array); * removes the first element of the returned array, the number of elements in the array, and the elements following it move forward, the number key name starts from 0. the associated key name remains unchanged * If the array is empty or not an array, NULL * array_unshift (array, value,) is returned ,,,); * insert the value to the beginning of the array, with all numbersIndexThe technology starts from 0 again. The Association key name remains unchanged ** array sorting * Key-value sorting * sort (array, []); the array value is sorted from small to large, if the operation is successful, true is returned. otherwise, false is returned. * rsort (array [],) is used to sort the array values from large to small. if the operation is successful, true is returned, otherwise, false * array sorting with key names ignored * usort (array, funcname) is returned; user-defined functions are called to sort arrays * value sorting with key names ignored ** asort () sort the value of the reserved key name * arsort () sort the value of the reserved key name * uasort () * =========== * sort by key name * ksort () sort by key name, mainly used to associate the array * krsort () to sort by key name in reverse order * uksort () user-defined function sorting * =========== * Natural sorting * natsort (); natural sorting * natcasesort () natural sorting, ignore case sensitivity ** array calculation * array_sum () calculation array elements and * array merging * array_merge (array1, array2); then the key name will be re-connected in a continuous mannerIndex* Array1 + array2 only retains the first key name for the same key name * if you want to completely retain the original array and only want to append the new array to the end, use the + operator * array_merge_recursive () recursive merge array * if the input array contains the same string key name, these values will be merged into an array, which will be recursive, therefore, if a value is an array, this function merges it into another array according to the corresponding entries. However, if the array has the same array key name, the latter value will not overwrite the original value, but will be appended to the back. ** Array's difference set ** array_diff (array1, array2, array3,); returns the elements in array1 but not in other arrays * array_diff_assoc (array1, array2, array3 ...); returns the elements in array1 but not in other arrays. the key names are also compared. only when the key names and key values are the same is the ** intersection of arrays ** array_intersect (array1, array2,); returns the array intersection * array_intersect_assoc (array1, array2,); returns the array intersection, the key name is also compared to ** Other array functions * range (start, max, step). create an array in the range from start to max. step is the step size, the default value is 1 * array_unique () to remove the repeated value * array_reverse () in the array. reverse the array. if the second parameter is true Retained key name * array_rand (array, size); returns the key names of one or more units in the array at random, if there are multiple keys, an array * shuffle (array) containing multiple key names is returned. the array elements are disrupted, returns FALSE or TRUE ***** // var_dump (is_array (3); $ arr = explode (",", "I, am, hello, 3 "); print_r ($ arr); echo implode ($ arr); // array_values () $ arr = array_values (array ('name' => 'daiyutage ', "age" => 20); print_r ($ arr); $ arr = array_keys (array ('name' => "daiyutage", "age" => 20 )); print_r ($ arr); var_dump (array_key_exists ('name', ar Ray ("name" => "daiyu"); var_dump (array_flip (array ("a" => 1, "B" => 1, "ddd" => 33); echoin_array ("daiyutage", array ("name" => "daiyutage ")); $ arr = array ("name" => 1); echo isset ($ arr ['name']); $ foo = array ("Robert" => "Bob ", "Seppo" => "Sepi", "name" => 3324); $ bar = each ($ foo); print_r ($ bar ); $ bar = each ($ foo); print_r ($ bar); $ info = array ("name", "haha"); unset ($ ); list ($ a [0], $ a [1]) = $ info; // print_r ($ a); /// $ name = "Diayutage"; // extract (array (// "name" => "xue", // "age" => 22, // "school" => "lut" //), EXTR_PREFIX_SAME, 'wx '); // echo $ name, "", "$ age ","", "$ school", "", $ Wx_name; // Textbook, 1, 2, 3. read a book hundreds of times, its meaning is self-existent. // compact $ firstname = "Peter "; $ lastname = "Griffin in"; $ age = 38; $ color = "red"; $ rs = array ("color", "fx "); // $ result = compact ("firstname", "lastname", "age", $ rs); // print_r ($ result); $ arr = array ("", "xx" => "B", 6 => "c", "d", "e"); // prin T_r (array_slice ($ arr, 2,-1, true); // array_splice ($ arr, 1,-4, "xxxxx "); // print_r ($ arr); // print_r (array_chunk ($ arr, 2, false); // print_r (array_pad ($ arr,-10, 33 )); // print_r (array_push ($ arr, "daiyutage", "fff"); // echo array_pop ($ arrs); // echo array_shift ($ arr ); array_unshift ($ arr, array ("hasdf", "sf"); $ fruits = array ("lemon", "sdfsf" => "orange", "banana ", "apple"); rsort ($ fruits); function cmp ($ a, $ B) {return $ a = $ B? 0: $ a <$ B? -;} // $ Brr = array ("fsf", "fs" => 3, 10 => 2, 4 => 244,3244); // ksort ($ brr ); // print_r ($ brr); // print_r (array_merge ($ fruits, $ brr); // The key name is reconnected in a continuous manner.Index// $ A = array (3 => "red", "hello", "hello"); // $ B = array ("red", "fe "); // print_r (array_intersect_assoc ($ a, $ B); // var_dump (range (0, 12, 9); // print_r (array_reverse ($ fruits )); // print_r (array_rand ($ fruits); // (shuffle ($ fruits); // print_r ($ fruits); // ** time zone setting * date_default_timezone_set () set the time zone. if the time zone is incorrect, E_WARNING instead of E_STRICT is thrown. Case insensitive * date_defalut_timezone_get () obtain the time zone * China time zone is Asia/Shanghai or PRC ** // echo date_default_timezone_get (); // error_reporting (E_ALL ); // date_default_timezone_set ("PRC"); // echo date_default_timezone_get (); // * Differences between CGI, PHP_mod, and FastCGI * common CGI gateway protocol * when a client requests a server, the server fork a process and execute php. the cgi program parses the php page, parses the process for destruction, and returns to the server. * for each request process, fork-> Execute-> destroy, the efficiency is very low, the * php_mod * php interpreter consumes a lot of system resources to start with the apache server in the form of a module. it uses the enhanced version of * FastCGI * CGI of the same process, which is equivalent to a middle layer, use a process, client> server> FastCGI> php to explain the instance. FastCGI uses a process resident memory and creates multiple CGI instances. * The communication between apache and FastCGI is tcp, that is, FastCGI can be a local host or a remote host * the communication between apache and CGI isInter-process communication, Must be for the same host * Summary: cgi: several processes need to be enabled; fastcgi: an additional process needs to be enabled; php_mod: no additional process needs to be enabled, because the PHP parser has been integrated into the web server, it is in the same process as the web server. ** Php_mod configuration method * in apache, httpd. * 1 LoadModule php5_module "C:/php5/php5apache2_2.dll" // line 1272 PHPinidir "C:/php5/php. ini "3 // modify the configuration 4 DirectoryIndex index.html index. php // Append index. php5 AddType application/x-httpd-php. add * CGI configuration method ** around php // line 408 // error_reporting (E_ALL); // setcookie ("haha "); /** cookie and session * cookie ['login'] = true; * A accesses * session box opening * session ['login'] = true; * B accesses the * session box and opens * session ['login'] = true; * The session is in the memory. if the session of each client is not distinguished, * The session cannot be used. Therefore, you need to associate the session of each request with the client * method: * when the first request is sent to the server, the server generates a session_id, * send the session_id to the browser through the http header. the browser saves the session_id in the local cookie. * When the server is requested again, the browser sends this cookie, the server uses session_id in the local cookie to access the session of the client after receiving the request. ** when the cookie is disabled, how to use session * php has two Default session transmission methods * 1. cookie * 2.url, such. php? Sid = xxx, or post submission, manually add sid through url * url by setting php. ini parameter, automatically added to the url * session. use_cookie = 1 * session. use _> 0 * session. use. trans_id = 1 * then php will automatically add PHPSESSION = XXXX ** 3 to the url. file Save sid. The first page stores the sessionid in the file, and the second page first obtains the sessionid from the file to determine whether to log on * 4. the database stores the sid, which is the same as the file principle ** when the cookie is disabled, the server will not send the cookie to the server when browsing the request, so the server will not receive the cookie = PHPSESSION, you cannot use session * use url * to get session_id with session_id () after the session is enabled on the previous page, then it is passed to the next page in get/post mode * the second page uses this sessio_id to set session_id (), and starts session_start (), you can use the session passed in. * Note: session_id () must be called before session_start (). ***/session_start (); $ _ SESSION ['login'] = "daiyutage"; // $ sid = session_id (); echo "Another page ";
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above describes php learning 01, including include, inter-process communication, objects, indexes, and static methods. I hope to help anyone who is interested in PHP tutorials.