Php/javascript/css/jquery Common Knowledge Daquan detailed finishing 1th/2 page _php tips

Source: Internet
Author: User
Tags constant explode garbage collection strlen type null variable scope visibility smarty template

1. What is the definition of a variable? How do I check that a variable is defined? How do I delete a variable? How do I detect if a variable is set?


$ defines whether the isset ()//check variable is set


Defined ()//Detect constants are set


Unset ()//Destroy the specified variable


Empty ()//detect variable is empty





2. What is a variable variable?
The variable name of a variable can be set and used dynamically.


$a = ' Hello ', $ $a = ' world ', ${$a}=hello world


3. What kinds of variable assignment methods?


1) Direct Assignment 2) assignment value of 3) reference assignment





4. What is the difference between a reference and a copy?
Copy is to copy the original variable content, copy the variable and the original variable using their own memory, do not interfere.


A reference is equivalent to a variable's alias, which is actually accessing the same variable's content with a different name. When you change the value of one of these variables, the other changes as well.





5. What are the basic data types for variables in PHP?
PHP supports 8 original data types including:


Four scalar types (Boolean boolean, Integer interger, floating point float/double, strings string)


Two types of composite (array arrays, object objects)


Two special types of resources (resource Resource,null)





6. What is considered false when other types are converted to Boolean types?


Boolean false, Integer value 0, floating-point value 0.0, white string, string ' 0 ', empty array, special data type NULL, no set variable.





In which cases does the empty () function return true?


Boolean false, Integer value 0, floating-point value 0.0, white string, string ' 0 ', array () empty array, special data type null, no attribute object, no assigned variable.





7. If a variable $a is defined, but no initial value is assigned


So $a==0?    $a ==false? $a = = ""?


$a ==null?     $a ===null? Answer:echo=> There's nothing, var_dump=>null


Empty ($b) ==true? ———————————— echo=>1, Var_dump=>bool (True)


What if the output $a++ at this point? There's nothing ——————— echo=>, Var_dump=>null.


If output + + $a how much? ————————— echo=>1, Var_dump=>int (1)





8. How does a string turn into an integer, how many ways? How does it happen?
Coercion type conversion: (integer) string variable name;


Direct conversion: Settype (string variable, integral type);


Intval (string variable);



9. What is the biggest difference between scalar data and arrays?
A scalar can hold only one data, while an array holds multiple data.





10. How do constants define? How do I detect if a constant is defined? What data types can the value of a constant be?


Define ()//define constants, defined ()//Check whether constants are defined


The value of a constant can only be a scalar type of data.





11. Constants are divided into system built-in constants and custom constants. What are some of the most common system built-in constants?
__file__, __line__, Php_os, php_version





12. If you define two of the same constants, which of the former and the latter work?
The former works because constants cannot be redefined or undefined once they are defined.



13. What are the differences between constants and variables?



1 There is no $ symbol before the constant;


2 constants can only be defined by define (), not by assignment statements;


3 constants can be defined and accessed anywhere, and variables have global and local points;


4 constants cannot be redefined or redefined once defined, while variables are redefined by assignment;


5 The value of a constant can only be scalar data, and the database type of the variable has 8 original data types.





What are some of the predefined global array variables commonly used in PHP?
There are 9 of the most predefined built-in array variables:


$_post, $_get, $_request, $_session, $_cookie, $_files,$_server, $_env, $GLOBALS





15. Where are the constants most commonly used in actual development?
1 The information connected to the database is defined as a constant, such as the user name, password, database name and host name of the database server;


2 The site's partial path is defined as a constant, such as the Web absolute path, smarty installation path, model, view or Controller folder path;


3 The public information of the website, such as the website name, the website keyword and so on information.





16. What are the advantages of the function?
Improve the maintainability of the program, improve the reliability of the software, improve the reusability of the program and improve the efficiency of program development





17. How do I define a function? Is the function name case-sensitive?


1 use function keywords;


2 function naming rules and variables, starting with letters or underscores, not starting with numbers;


3 The function name is case-insensitive;


4 function names may not use the name of a function that has already been declared or the system has built itself.





18. What is the variable visibility or variable scope?


is the scope of the variable in the program. According to the visibility of variables, variables are divided into local variables and global variables.





19. What are local variables and global variables? Can you call global variables directly within a function?


A local variable is a variable defined within a function, and its scope is the function in which it resides. If the function has a variable with the same name as the local variable, the program thinks that the two are completely different two variables. When the function is exited, the local variables are cleared at the same time. Global variables are variables defined outside all functions that are scoped to the entire PHP file, but are not available within user-defined functions. If you must use global variables internally within a user-defined function, you will need to use the Global keyword declaration. That is, if you add Golbal to the variables in the function, you can access the global variable inside the function, not only by using the global variable, but also by assigning a value to the global variable. Global variables can also be invoked using $GLOBALS [' var '].





21. What is a static variable?
If a variable defined within a function is declared using the keyword static, then the variable is a static variable.


Variables in a generic function after the function call is finished, the data it stores is purged and the memory space is freed up. When a static variable is used, the variable is initialized the first time the function is invoked, the variable is not purged when it is initialized, and when the function is called again, the static variable is no longer initialized, and the value of the last function execution is saved. You can say that a static variable is shared among all calls to that function.





What are the ways in which functions pass parameters in PHP? What's the difference between the two?


Passed by value and delivered by address (or by reference)


(1) Passing by value: The variable to be passed is stored in a different space than the variable passed to the function. So the body of the function


The value of the variable is modified without affecting the original variable value.


(2) Delivery by address: Using the & symbol, indicating that the parameter is passed the value in the manner of the address. Instead of passing the specified numeric or target variable in the main program to the function, the value or variable's memory storage block address is imported into the function, so the variable in the body of the function and the variable in the main program are the same in memory. The modification of the function body directly affects the value of the variable outside the function body.








23. What is a recursive function? How do I make a recursive call?
A recursive function is actually a function that calls itself, but the following two conditions must be met:


1 each time the call itself, must be closer to the final result;


2 must have a definite recursive termination condition, which does not cause a dead loop.


An example is provided:


In the actual work will often be used when traversing the folder.


If there is an example where you want to get all the files under directory windows, walk through the Windows directory and, if you find a folder in it, call yourself, keep looking down, and so on,


This means iterating through all the files until the folder is traversed.





24. Determine if a function exists?


Function_exists (String $function _name) returns True if it exists, false if it does not exist.





What is the difference between func () and @func ()?


The second function call fails without an error, and the first one will complain





what are the usages and differences between the include () and require () functions? Include_once () and require_once ()?


The error level is not the same as the include and require errors


Include_once () and require_once () before loading to determine if they have been imported





27. What is the difference between the predecessor + + and the Post + +?


The predecessor + + is to increase the variable by 1 first, and then assign the value to the original variable;


Post + + is to first return the current value of the variable, and then increase the variable's current value by 1.





28. String operator "." What is the difference with the arithmetic operator "+"?
When used between "a" "B", it is considered to be a hyphen. If the two are +, PHP will consider it an operation.


1 if the number of strings on both sides of the + number is composed of numbers, the string will automatically be converted to integral type;


2 if the + number on both sides is a pure letter, then output 0;


3 if the string on both sides of the + number begins with a number, the number at the beginning of the string is intercepted and the operation is performed.





29. What is the three-mesh (or ternary) operator?
Select one of the other two expressions based on the result of one expression.


For example: ($a ==true)? ' Good ': ' bad ';





30. What are the control process statements?


1: Three kinds of program structure sequence structure, branch structure, circulation structure


2: Branch: If/esle/esleif/switch/case/default


3:switch need to be aware of:


A constant in a case clause can be an integer, a string constant, or a constant expression that is not allowed to be a variable.


In the same switch clause, the value of the case cannot be the same, otherwise only the value in the first occurrence of the case can be taken.


4: Loop for while Do...while


Do...while must be followed by a semicolon ending.


The difference between while and do...while


The difference between 5:break and continue.


A break can terminate a loop.


Continue does not break strong, can only terminate this cycle and into the next cycle.





31. What is the concept of arrays? What are the two types of arrays divided by index? What are the two ways to assign an array?


An array is a variable (compound variable) that can store a set or series of values.


Indexed Array (index value is number, starting with 0) and associative array (with string as index value)


What are the two ways to assign an array?


There are two main ways to declare an array.


1. Declare an array through the array () function;


You can define indexes and values separately by Key=>value, or you can define an index subscript for an array, giving only the element values for the number of groups.


2. Assigning values directly to an array element does not require calling the array () function. For example:


$arr [0] = 1; $arr [1] = 2;


Special attention:


The subscript of an array is treated as an integer if it is a string value equivalent to an integer (but cannot begin with 0).


For example: $array [3] refers to the same element as $array [' 3 '], and the reference to $array [' 03 '] is another element.





32. How do arrays traverse?


①for Cycle


②foreach loops, which is the most common way to traverse. Usage is as follows: foreach ($arr as $key => $value) {}


③list each and while together loop





How does the pointer point to a Foeach array?
When the list ()/each ()/while () loops the array, how does the pointer point to it?


When foreach starts executing, the pointer inside the array will automatically point to the first cell. Because foreach is manipulating a copy of the specified array, rather than the array itself. After each () array, the array pointer stays in the next cell in the array or at the end of the array. If you want to use each () to traverse an array again, you must use Reset ().


Reset () returns the internal pointer of the array back to the first cell, returning the value of the first array cell.





34. How do I calculate the length of an array (or count all the elements in an array)? How does a string take a length?
Count ()--counts the number of elements in the array.


You can use count (array name) or count (array name, 1), and if you have the second argument and the number 1, the number of recursive statistic array elements. If the second argument is number 0, it is equivalent to the count () function with only one parameter.


sizeof ()--alias of Count () (count-count the number of cells in an array or the number of attributes in an object)


String: strlen ()-Get string length


Mb_strlen ()-get string length





35. What are the common functions associated with the array?
1 Count--(sizeof alias)-count the number of cells in an array or the number of attributes in an object


For example: int count (mixed $var [, int $mode]) $var is usually an array type, and any other type has only one unit. The default value for $mode is 0. 1 to open recursive array count


2) In_array (mixed $needle, array $haystack [, BOOL $strict])-Checks whether a value exists in the array. If the needle is a string, the comparison is case-sensitive. If the third argument strict a value of TRUE, the In_array () function also checks whether the needle type is the same as the haystack.


3) Array_merge (array $array 1 [, Array $array 2 [, Array $ ...]]) merges one or more arrays of cells, and the values in an array are appended to the previous array. Returns an array as the result.


Special NOTE: If the input array has the same string key name, the value after the key name overrides the previous value. However, if the array contains a numeric key name, the subsequent value will not overwrite the original value, but append to the back.


If only one array is given and the array is a numeric index, the key name is sequentially indexed





4 conversion between the array and the string


(1) Explode (string $separator, string $string [, int $limit]) uses a separator character to separate a string.


(2) Implode (string $glue, array $arr) uses a connector to connect each cell in the array to a string. Join as Implode alias


5 sort (Array & $array [, int $sort _flags])-arrays are sorted by value, and when this function ends, the array cells are rescheduled from lowest to highest.





36. Array Merge function Array_merge () and arrays addition operation $arr + $arr 2 What is the difference?
Array_merge ()-> use Array_merge (), if an associative array is merged, if the array has the same key name, then the following value overrides the former; if it is a numeric indexed array merge, it is not overwritten, but the latter is appended to the former. The "+"-> uses array addition operations, unlike Array_merge (), an addition operation, whether an associative array or a numeric indexed array, discards the value of the same key name, which means that only the element with the first occurrence of the key is retained, and later elements with the same key name are not added.





37. What is the difference between single and double quotes when the string is defined?
Single quotes load faster than double quotes


What is the difference between print_r (), print (), and ()?


(1) Echo is syntax, Output one or more strings, no return value;


(2) Print is a function, can not output arrays and objects, output a string,print has a return value;


(3) Print_r is a function that can output an array. Print_r is a more interesting function, you can output stirng, int, float, array, object and so on, output array will be expressed in the structure, Print_r output to return True when successful, and Print_r can pass Print_r ($ Str,true), so that the print_r does not output and returns the value of Print_r processing. In addition, for Echo and print, the basic use of ECHO is mostly because it is more efficient than print.





39. What are the string processing functions according to the functional classification? What is the function of these functions?
A. String output function


(1) Echo $a, $b, $c ...; is a language structure, not a real function.


(2) print ($a) This function outputs a string. Returns 1 if successful, failure returns 0


(3) Print_r ($a)


(4) Var_dump ($a); Can output type, length, value


B. Remove the string from the end of the space function: Trim LTrim rtrim (alias: chop) Use the second parameter, you can also remove the specified characters.


C. Escape string function: Addslashes ()


D. Get the string length function: strlen ()


E. Functions to intercept string lengths: substr ()


F. Retrieving String functions: Strstr (), Strpos ()


G. Replacement string function: Str_replace ()





40. Please give the correct answers to the following questions?
1. $arr = Array (' James ', ' Tom ', ' Symfony '); Please split the value of the $arr array with ', ' and merge it into string output? echo implode (', ', $arr);


2). $str = ' jack,james,tom,symfony ';           Would you please split the $str with ', ' and place the split value in the $arr array? $arr = Explode (', ', $str);


3). $arr = Array (3,7,2,1, ' d ', ' abc ');           Sort the $arr in order from big to small and keep their key values unchanged? Arsort ($arr); Print_r ($arr);


4). $mail = "gaofei@163.com"; Please remove this mailbox's domain (163.com) and print it to see how many methods can be written?


Echo strstr ($mail, ' 163 ');


Echo substr ($mail, 7);


$arr = Explode ("@", $mail); echo $arr [1];


5. If there is a string, the string is "123,234,345,". How do I cut off the last comma of this string?


6. What are some of the functions that get random numbers? Mt_rand () and Rand () which executes faster?





41. Page characters appear garbled, how to solve?


1. First consider whether the current file is set up with a character set. See if the META tag is written in CharSet, if it's a PHP page you can also see if it's


The charset is specified in the header () function;


For example:


<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>


Header ("Content-type:text/html;charset=utf-8");


2. If you set the character set (that is, CharSet), then determine if the current file save the encoding format is consistent with the character set of the page,


The two must remain united;


3. When it comes to extracting data from a database, it is important to judge whether the character set of the database query is consistent with the character set of the current page.


For example: mysql_query ("Set names UTF8").





42. What is the regular expression? What are some of the most common and regular-related functions in PHP? Please write a regular expression of email, China Mobile phone number and landline number.
A regular expression is a grammatical rule used to describe the pattern of character permutations. Regular expressions are also called pattern expressions.


Web site development Regular expressions are most commonly used for client-side validation before form submission information.


For example, verify that the user name is entered correctly, whether the password input meets the requirements, email, mobile phone number and other information input is legal


In PHP, the expression is primarily used for string segmentation, matching, lookup, and substitution operations.





Preg series functions can be processed. The following are the specific ones:


String Preg_quote (String str [, String delimiter])


Escape Regular Expression Single-character the special characters of an expression include:. \\ + * ? [ ^ ] $ ( ) { } = ! < > | :。


Preg_replace--Performs search and replace of regular expressions


Mixed preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit]


Preg_replace_callback--using callback functions to perform search and replace of regular expressions


Mixed Preg_replace_callback (mixed pattern, callback callback, mixed subject [, int limit])


Preg_split--Splitting a string with a regular expression


Array Preg_split (string pattern, string subject [, int limit [, int flags]])





Common Regular Expressions:


Chinese:/^[\u4e00-\u9fa5]+$/


Mobile number:/^ (0?1\d{10}$/)?


EMAIL:


/^[\w-]+[\w-.]? @[\w-]+\. {1} [A-za-z] {2,5}$/


Password (in security level):


/^ (\d+[a-za-z]\w*| [a-za-z]+\d\w*) $/


Password (high security level):


/^ (\d+[a-za-z~!@#$%^& () {}][\w~!@#$%^& () {}]*| [a-za-z~!@#$%^& () {}]+\d[\w~!@#$%^& () {}]*) $/





What is the difference between preg_replace () and Str_ireplace () two functions in use? How do the Preg_split () and split () functions work?


Preg_replace-performs search and replace of regular expressions


Ignore case version of Str_ireplace-str_replace () str_replace-substring substitution


Preg_split-split strings with regular expressions


Split-the string into an array with a regular expression





45. What are the main functions that get the current timestamp? Use PHP to print out today's time, the format is 2010-12-10 22:21:21?


Use PHP to print out the day before the format is 2010-12-10 22:21:21? How do I turn 2010-12-25 10:30:25 into a unix timestamp?


echo Date ("Y-m-d h:i:s", Strtotime (' -1,days '));


Date (' y-m-d h:i:s ', Time ());


$unix _time = Strtotime ("2009-9-2 10:30:25");//Turn into UNIX timestamp


echo Date ("Y-m-d h:i:s", $unix _time);//format as normal time format





46. When you use get to pass the value in the URL, if the Chinese appears garbled, which function should be used to encode Chinese?
When the user submits the data in the website form, in order to prevent the script attack (such as user input <script>alert ();</script>), what should the PHP end receive the data to handle?


Use UrlEncode () to encode Chinese and use UrlDecode () to decode it.


Use Htmlspecialchars ($_post[' title ') to filter table conveys parameters to avoid scripting attacks.





48. What is the difference between mysql_fetch_row () and Mysql_fetch_assoc () and mysql_fetch_array?


The first is to return the row in the result set as an indexed array, the second to return an associative array, and the third to either return an indexed array or return an associative array, depending on its second argument Mysql_both mysql_num mysql_assoc default is Mysql_both


$sql = "SELECT * FROM table1";


$result = mysql_query ($sql);


Mysql_fetch_array ($result, mysql_num);





49. Please say what you have learned about returning as a function of resources?
Answer: fopen (open file)


Imagecreatefromjpeg (PNG gif)-Create a new image from a JPEG file


imagecreatetruecolor-Create a new true color image


imagecopymerge-copy and merge part of image


imagecopyresized-copy partial images and resize them


Mysql_connect-Open a connection to the MySQL server


mysql_query (); Returns the resource only if this is successful when the select is executed, and the failure returns false





50. What is the function to open and close the file separately? What is the function of file reading and writing? Which function is to delete a file?


What is the function that determines whether a file exists or not? Which function is the new directory?





51. What details should be paid attention to file uploading? How do I save a file to a specified directory? How to avoid uploading file duplicate name problem?
1. The first is to open in the php.ini file upload;


2. There is a maximum allowable upload in the php.ini, the default is 2MB. Can be changed when necessary;


3. The upload form must remember to write the enctype= "Multipart/form-data" in the form label;


4. Method of submission must be post;


5. Set the form control of type= "file";


6. To pay attention to the size of the upload file max_file_size, file types meet the requirements, upload the stored path exists.


You can get the file suffix by uploading the filename, and then rename the file by using the timestamp + file suffix, which avoids the duplicate name. You can set up your own upload file to save the directory, together with the filename to form a file path, using Move_uploaded_file (), you can complete the file save to the specified directory.








$_files is a few-dimensional array? What are the index subscripts for the first and second dimensions? What do you need to be aware of when uploading files in bulk?
Two-dimensional array. The first dimension is the name of the upload control, and the two-dimensional subscript is name/type/tmp_name/size/error.





what are the main functions of the header () function? What do you pay attention to during your use?


For:


Header () Send HTTP header information


-header ("content-type:text/html; Charset=utf-8 ");-------------------//Current page output is HTML, encoded in UTF-8 format


-<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>


-header ("content-type:image/png gif jpeg");----------------------------------//Current page output is in the form of a picture


-header ("refresh:5;url=http://www.1004javag.com/five/string.php");--//page 5 seconds to jump to the new URL


-header ("location:http://1004javag.com/five/string.php");-----------//Page redirection


54. If the header () function is used when downloading files?


Answer: Header ("Content-type:application/octet-stream;charset=utf-8"); What's the difference between adding a utf-8 here and defining it? 、??


Header ("Accept-ranges:bytes");


Header ("Accept-length:". FileSize ($filedir. $filename));


Header ("content-disposition:attachment; Filename= ". $filedir. $filename);








55. What is AJAX? What is the principle of Ajax? What is the core technology of Ajax? What are the pros and cons of Ajax?
AJAX is the acronym for Asynchronous JavaScript and XML, and is a combination of JavaScript, XML, CSS, DOM, and many other technologies. ' $ ' is the alias of jquery.





The user's request in the page communicates asynchronously with the server via an AJAX engine, and the server returns the result of the request to the Ajax engine.


Finally, the Ajax engine decides to display the returned data to the specified location on the page. Ajax ultimately enables you to load all of the output from another page at a specified location on a page.


This enables a static page to obtain the return data information in the database. So Ajax technology implements a static Web page that communicates with the server without refreshing the entire page,


Reduced user latency while also reducing network traffic and enhancing the friendliness of the customer experience.





The advantages of Ajax are:


1. Reduce the burden on the server side, part of the previous work of the server to the client to execute, using the client idle resources for processing;


2. Update the page with only local refresh, increase the page response speed, and make the user experience more friendly.


The disadvantage of Ajax is that it is not conducive to SEO promotion optimization, because search engines can not directly access the content of Ajax requests.


The core technology of Ajax is XMLHttpRequest, which is an object in JavaScript.





What is jquery? What are the ways in which jquery simplifies Ajax?


jquery is a framework for JavaScript.


$.get (), $.post (), $.ajax (). $ is the alias of the jquery object.





The code is as follows:


$.post (URL address for asynchronous access, {' parameter name ': Parameter value}, function (msg) {


$ ("#result"). HTML (msg);


});





$.get (URL address for asynchronous access, {' parameter name ': Parameter value}, function (msg) {


$ ("#result"). HTML (msg);


});





$.ajax ({


Type: "Post",


Url:loadurl,


Cache:false,


Data: "Parameter name =" + parameter value,


Success:function (msg) {


$ ("#result"). HTML (msg);


}


});








57. What is session control?
Simply speaking, session control is a mechanism for tracking and identifying user information. The idea of the session control is to be able to track a variable in the website, through this variable, the system can identify the corresponding user information, according to the user information can know the user rights, so as to show the user suitable for their corresponding permissions of the page content. At present, the most important way of conversation tracking is cookie,session.





58. Basic steps for session tracking


1). Access Session Object 2 associated with the current request. Find information related to a session


3). Store session information 4). Discarding session data





59. What are the precautions for using cookies?
1) Setcookie () can not have any page output, is a space, blank line can not;


2 Setcookie () after the current page call $_cookie[' CookieName '] will not have output, must refresh or to the next page before you can see the COOKIE value;


3 different browsers for cookie processing, the client can disable cookies, the browser can also idle the number of cookies, a browser can create a maximum of 300 cookies, and each can not exceed 4kb,


The total number of cookies that can be set per Web site cannot exceed 20.


4 cookies are stored on the client, and the user disables the cookie, so Setcookie will not work. So you can't rely too much on cookies.





60. When using the session, what can be used to represent the current user and thus differentiate with other users?
SessionID, the current session_id can be obtained through the session_id () function.





What are the steps to use for session and cookies respectively? What is the life cycle of sesssion and cookies? What is the difference between session and cookie?


Cookies are stored on the client machine, and Cookie,cookie values that are not set to expire are saved in the machine's memory, and the cookie disappears automatically as soon as the browser is closed. If you set the expiration time for a cookie, the browser saves the cookie as a text file to your hard disk, and the cookie value remains in effect when you open the browser again.


Session is to save the information that the user needs to store on the server side. The session information for each user is stored on the server side like a key value pair, where the key is SessionID, and the value is that the user needs to store the information. A server is a SessionID to differentiate which user's session information is stored.


The biggest difference between the two is that the session is stored on the server side, and the cookie is on the client. Session security is higher, and cookies are less secure.


Session has a very important weight in web development. It can record the user correctly logged in to the server's memory, when the user in this capacity to access the site management background, no need to log in again to be identified. Users who do not log on correctly do not allocate session space, even if they enter the admin admin access address and cannot see the page content. The user's permission to operate the page is determined by session.


To use session steps:


1. Start session: Use the Session_Start () function to start.


2. Register session: Add elements directly to the $_session array.


3. Use sessions: Determine if the session is empty or if it is already registered, and if it already exists, it can be used as a normal array.


4. Delete session:


1. You can use unset to delete a single session;


2. Use $_session=array () to unregister all session variables at once;


3. Use the Session_destroy () function to completely destroy the session.


How do I use cookies?


1. Record part of user access information


2. Passing variables between pages


3. Storing the Internet pages you view in the Cookies temporary folder can improve your browsing speed later.


Create Cookie:setcookie (String cookiename, string value, int expire);


Read Cookie: $_cookie to read the value of the cookie on the browser side through the Super Global array.


Delete Cookie: There are two ways


1. Manual removal Method:


Right-click the browser properties, you can see the deletion of cookies, the operation can be deleted all cookie files.


2.setcookie () Method:


This is the same as setting a cookie, but at this point the cookie value is set to NULL with a valid time of 0 or less than the current time stamp.





62. How do I set the name of a cookie to be username, the value of Jack, and let this cookie expire in a week?
How many cookies can a browser generate, and how much should each cookie file not exceed?


Setcookie (' username ', ' Jack ', Time () +7*24*3600);


Up to 20 cookies can be generated, each up to no more than 4K





63. What do I need to do before I set up or read the session?


Can be opened directly in the php.ini Session.auto_start = 1 or in the page head with Session_Start ();


You cannot have any output before opening session,session_start (), including blank lines.





64. In the actual development, session in which occasions use?
Sessions are used to store user logon information and to pass values across pages.


1) commonly used in the user login after the success of the user login information assigned to the session;


2) use in the Verification code picture generation, when the random code generation assigns the value to the session.





65. How many forms of cancellation session?
Unset () $_session=array (); Session_destroy ();





66. What is OOP? What are classes and objects? What is a class attribute?


OOP (object oriented programming), or object-oriented programming, where two of the most important concepts are classes and objects.


Everything in the world has its own properties and methods through which different substances can be divided.


A collection of properties and methods forms a class, which is the core and foundation of object-oriented programming,


A class is used to effectively manage the fragmented code that implements a feature.


A class is just an abstract model with some features and attributes, and a real application requires an entity that requires instantiating the class, which is the object after the instantiation. ★ Class is an abstract concept of an object, which is an instantiation of a class.


Object is an advanced array, an array is the most primitive object, and the same object can traverse


OOP has three main features:


1. Encapsulation: Also known as information hiding, is to separate the use and implementation of a class, retain only part of the interface and methods and external contact, or only to expose some of the methods used by developers. So developers only need to pay attention to this class how to use, and do not care about its specific implementation process, so that can achieve MVC division of work, but also can effectively avoid the interdependence between programs, to achieve code modules loose Lotus.


2. Inheritance: The subclass automatically inherits the properties and methods in its parent class, and can add new properties and methods or override some of the properties and methods. Inheritance adds to the reusability of your code. PHP only supports single inheritance, which means that a subclass can have only one parent class.


3. Polymorphism: Subclasses inherit properties and methods from the parent class, and some of the methods are overridden. So many subclasses have the same method, but the objects that are instantiated by these subclasses can get completely different results when they invoke the same method, and this technique is polymorphism. Polymorphism enhances the flexibility of the software.





The advantages of OOP: 1, High code reusability (provincial code) 2, high maintainability of the Program (extensibility) 3, flexibility





67. What are the access modifiers for commonly used properties? What do you mean, separately?
Private,protected,public.


Outside of class: public, Var


Subclass: Public,protected, var


In this class: Private,protected,public, var


If you do not use these three keywords, you can also use the var keyword. However, Var cannot be used with permission modifiers. var-defined variables, which can be accessed in subclasses, and can be accessed outside of the class, equivalent to public


Class Front: Only add final,abstract


Front of attribute: Must have access modifier (Private,protected,public,var)


Method before: Static,final,private,protected,public, abstract





What are the three key words of $this and self, parent, respectively? In which situations are they used?


$this the current object self Current class parent current class parental class


$this is used in the current class to invoke properties and methods using->.


Self is also used in the current class, but requires:: Call. Parent is used in classes.





69. How to define constants in a class, how to call constants in a class, and how to call constants outside of a class.


A constant in a class is a member constant, which is the amount that does not change, and is a constant value.


Define constants using the keyword Const.


For example: const PI = 3.1415326;


Constant access and variables are not the same whether they are inside or outside the class, and constants do not need to instantiate objects.


The format of the access constants is called by the class name plus the scope action symbol (double colon).


namely: Class Name:: Class constant name;





70. Scope Operator:: How to use? In which situations are they used?


Calling a class constant calls a static method





71. What is the Magic method? What are some of the common magic methods?
A system-customized method that begins with __.


__construct () __destruct () __autoload () __call () __tostring ()





72. What is the construction method and the destructor method?
The constructor method is a member method that is automatically executed while instantiating an object, which is the function of initializing the object.


Before PhP5, a method that is identical to the class name is the construction method, and the PhP5 Magic Method __construct () is the construction method. If a constructor is not defined in a class, PHP automatically generates one, and the auto-generated constructor has no parameters and no action.


The format of the construction method is as follows:


function __construct () {}


Or: function class name () {}


A constructed method can have no parameters or multiple parameters.


The function and construction method of the destructor is just the opposite, it is called automatically when the object is destroyed, and the function is to free the memory.


The definition method of the destructor method is: __destruct ();


Because PHP has a garbage collection mechanism that automatically clears objects that are no longer in use and frees up memory, you can typically not create a destructor manually.





How does the __autoload () method work?


The basic condition of using this magic function is that the filename of the class file should be consistent with the name of the class.


When a program executes to instantiate a class, if the class file is not introduced before instantiating it, the __autoload () function is automatically executed. This function looks up the path to the class file based on the name of the instantiated class, and executes include or require to load the class file after it is judged to exist, and then the program continues executing if the file does not exist under the path.


Prompts for an error. Using a magic function that is loaded automatically eliminates the need to write many include or require functions.





74. What are abstract classes and interfaces? What are the differences and similarities between abstract classes and interfaces?


Abstract classes are classes that cannot be instantiated and can only be used as parent classes of other classes.


Abstract classes are declared by keyword abstract.


Abstract classes, like ordinary classes, contain member variables and member methods, the difference being that at least one abstract method is included in an abstract class.


Abstract methods do not have a method body, which is inherently overridden by a quilt class.


The format of the abstract method is: abstract function abstractmethod ();


Because only single inheritance is supported in PHP, interfaces are used if you want to implement multiple inheritance. This means that subclasses can implement multiple interfaces. The interface class is declared by the interface keyword, and the member variables and methods in the interface class are public, methods can not write the keyword public, and the method in the interface is not a method body. The methods in the interface are also innate to be implemented by the quilt class. Abstract classes and interfaces implement very similar functions, the biggest difference is that interfaces can achieve multiple inheritance. Whether to select an abstract class or an interface in an application depends on the specific implementation. Subclasses inherit abstract classes using extends, and subclasses implement interfaces using implements.


Does an abstract class have at least one abstract method??????


A: If a class is declared as an abstract class, there can be no abstract method


If there is an abstract method in a class, this class must be an abstract class





There are several parameters of __call, what is the type and what is the meaning?


The Magic Method __call () is that when a program calls a member method that does not exist or is not visible, PHP first calls the __call () method to store the method name and parameters of the nonexistent method.


__call () contains two parameters, the first parameter is the method name of the nonexistent method, and is a string type;


The second parameter is the array type for all parameters of the method that does not exist.


I think the __call () method is more important than debugging, you can locate the error. You can also catch exceptions and perform other workarounds if a method does not exist.





What is the purpose of smarty template technology?


In order to separate PHP from HTML, art and programmers do their own duties, do not interfere.





What are the main items of the Smarty configuration?


1. Introduction of smarty.class.php;


2. Instantiate the Smarty object;


3. Re-modify the default template path;


4. Re-modify the default path of the compiled file;


5. Re-modify the default configuration file path;


6. Re-modify the default cache path.


7. You can set whether to open cache.


8. You can set the left and right delimiters.





What details do smarty need to pay attention to in the course of use?


Smarty is a template engine based on the MVC concept, which divides a page program into two parts: The view layer and the control layer, which means that the Smarty technology separates the user UI from the PHP code. So programmers and artists do their own duties, do not interfere.


Smarty in the use of the process should pay attention to the following issues:


1. Properly configure Smarty. The main objective is to instantiate the Smarty object and configure the path of the smarty template file;


2.php page using assign assignment and display page;


3.smarty template file does not allow the occurrence of PHP code snippets, all annotations, variables, functions are included in the delimiter.


a.{}


B. foreach


C. If Else


D. Include


E. Literal





What is the concept of the KM MVC? What are the main tasks of each layer?
MVC (i.e. model-view-Controller) is a software design pattern or programming idea.


M refers to the model layer, V is the View view layer (display layer or user interface), and C is the controller controller layer.


The purpose of using MVC is to implement M and V separation, making it easy for a program to use a different user interface.


In the development of the website,


The model layer is generally responsible for increasing the deletion of database table information,


The view layer is responsible for displaying the page content,


The controller layer plays a moderating role between M and V, and the controller layer decides which method of the model class to invoke.


After execution, the controller layer decides which view layer to assign the result to.





Bayi. Method overrides and overloads in the Java language What do you mean, respectively? Is the overload of the PHP support method accurate? How do the PHP overloads mentioned in many reference books actually be properly understood?
For:


PHP does not support method overloads, and many of the PHP ' overloads ' mentioned in the book should be ' rewritten '





can the final keyword define member properties in a class?


A: No, the member properties of a class can be defined only by public, private, protected, Var





can the class defined by the final keyword be inherited?
A: The final defined class cannot be inherited



84. Talk about the use of static keywords? Can the static be used before class?
Can static be used with Public,protected,private? Can the construction method be static?


A: Static can be used before properties and methods, call the static property or method, as long as the class load is available, do not instantiate


Static cannot be used in front of class


Static can be used with public,protected,private, in front of the method;


▲ Construction method cannot be static





85. Can interfaces be instantiated? Can an abstract class be instantiated?
Answer: Interfaces and abstract classes cannot be instantiated





can I add an access modifier before the class? What are the access modifiers, if you can add them? Can it be a permission access modifier public,protected,private?


A: Class before you can add final,static;


★class can't add public,protected,private to the front.





87. Can I have no access modifiers before attributes in a class? is the modifier before the member variable only public,protected,private? What else could it be?


A: The attributes in a class must be decorated with a modifier, plus var in addition to those 3





88. If echo an array, what does the page output? What about an Echo object? Print an array or an object?


A: The page can only output "Array"; Echo an object appears "Catchable fatal Error:object of class T2 could not is converted to string in G:\php2\t2.php O N Line 33 "


Print an array is also only output "array", print an object appears "Catchable fatal Error:object of class T2 could not is converted to string in G:\php2\t 2.php "


▲print and Echo are the same.





when is the __tostring () Magic method automatically executed?


Does the __tostring () Magic method have to return a value?


When Echo or print an object, it is automatically triggered. and __tostring () must return a value





90. What is an abstract method?
A: There is an abstract before the method, and the method has no method body, and even "{}" cannot have





91. If there is a method in a class that is an abstract method and the class is not defined as an abstract class, does it make an error?


A: Yes, "Fatal error:class T2 contains 1 abstract method and must therefore is declared abstract or implement the remaining m Ethods (T2::ee) in "





92. If a class is an abstract class, and a method in a class is a non-abstract method, does it make an error?


A: No error, if a class is an abstract class, where there can be no abstract method, but a class has a method is an abstract method, then this class must be an abstract class





The final key word application should pay attention to the problem?


Classes that are defined with the final keyword prohibit inheritance.


Override is prohibited using the method defined by the final keyword.





95. How do I write a class if it inherits a parent class and implements multiple interfaces?
Writing format for example: Class Malehuman extends Human implements Animal,life {...}





96. What is a single point of entry?


The single point of entry is that the entire application has only one portal, and all implementations are forwarded through this portal,


For example, in the above we use index.php as a single point of entry for the program, of course this can be controlled by your own arbitrary.


A single point of entry has several major benefits:


First, some system global processing variables, classes, methods can be processed here. For example, you have to filter the data initially, you want to simulate session processing, you have to define some global variables, even you want to register some objects or variables into the register


Secondly, the structure of the procedure is clearer.





PHP offers 2 sets of regular expression libraries, what are the two sets?
(1) PCRE Perl-compatible regular expression preg_ as prefix


(2) POSIX Portable Operating System interface Ereg_ as prefix





98. The composition of regular expressions?
By atoms (ordinary character, such as English characters),


Metacharacters (characters with special functions)


Pattern modifier character


A regular expression that contains at least one atom





99. Does not use the Magic method the trigger time?
Timing of __isset () __unset ()


__sleep (), __wakeup () are called when the object is serialized


If the object is serialized without writing the __sleep () method, all member properties are serialized and the __sleep () method is defined, and only the variables in the specified array are serialized. Therefore, this function is useful if you have a very large object and you do not need to store it completely.


The purpose of using __sleep is to turn off any database connections that the object might have, commit the waiting data, or perform similar cleanup tasks. Also, this function is useful if you have a very large object and you do not need to store it completely.


The purpose of using __wakeup is to reconstruct any database connections that may be lost in serialization and to handle other reinitialization tasks.





Current 1/2 page 12 Next read the full text
Related Article

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.