In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "what is the common knowledge of PHP/Javascript/CSS/jQuery", the content is simple and clear, and I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "what is the common knowledge of PHP/Javascript/CSS/jQuery?"
1. How are variables defined? How do I check if a variable is defined? How do I delete a variable? How to detect whether the variable is set?
$define isset () / / check whether the variable is set
Defined () / / detect whether the constant is set
Unset () / / destroy the specified variable
Empty () / / detects whether the variable is empty
two。 What is a variable?
The name of a variable can be set and used dynamically.
$a = 'hello', $a =' world', ${$a} = hello world
3. What are the ways to assign variables?
1) Direct assignment 2) assignment between variables 3) reference assignment
4. What's the difference between quoting and copying?
Copy is to copy the contents of the original variables, the copied variables and the original variables use their own memory, do not interfere with each other.
To refer to an alias equivalent to a variable is to access the contents of the same variable under a different name. When you change the value of one of the variables, so does the other.
5. What are the basic data types of variables in php?
Php supports eight raw data types, including:
Four scalar types (Boolean boolean, integer interger, floating point float/double, string string)
Two compound types (array array, object object)
Two special types (resource resource,NULL)
6. Which types are considered false when other types are converted to boolean types?
Boolean value false, integer value 0, floating point value 0, blank string, string '0values, empty array, special data type NULL, no variables set.
Under what circumstances does the empty () function return true?
Boolean value false, integer value 0, floating point value 0, blank string, string '0values, array () empty array, special data type NULL, objects with no attributes, no variables assigned.
7. If a variable $an is defined, but no initial value is assigned
So $axioms 0? $a==false? Is it $a million dollars?
$a==NULL? $a===NULL? Answer: echo= > nothing, var_dump= > NULL
Empty ($b) = = true? -echo= > 1, var_dump= > bool (true)
How much is the output of $averse + at this time? -echo= > nothing, var_dump= > NULL
How much is the output + + $a? -echo= > 1, var_dump= > int (1)
8. How can a string be converted to an integer? How do you do that?
Cast: (integer) string variable name
Direct conversion: settype (string variables, integers)
Intval (string variable)
9. What is the biggest difference between scalar data and arrays?
A scalar can hold only one data, while an array can hold multiple data.
10. How do you define a constant? How to detect whether a constant is defined? Which data types can only be the value of a constant?
Define () / / define constants, defined () / / check whether constants are defined
The value of a constant can only be data of scalar type.
11. Constants are divided into system built-in constants and custom constants. Please name the most common system built-in constants?
_ _ FILE__, _ _ LINE__, PHP_OS, PHP_VERSION
twelve。 If two identical constants are defined, which of the former or the latter works?
The former works because constants cannot be redefined or undefined once they are defined.
13. What is the difference between constants and variables?
1) there is no $sign 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 can be divided into global and local.
4) once a constant is defined, it cannot be redefined or undefined, while a variable is redefined by assignment.
5) the value of a constant can only be scalar data, and the database type of a variable has eight primitive data types.
14. What are several predefined global array variables commonly used in PHP?
There are nine predefined built-in array variables:
$POST, $GET, $REQUEST, $SESSION, $COOKIE, $FILES,$_SERVER, $ENV, $GLOBALS
15. Where are 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) define some paths of the site as constants, such as web absolute path, smarty installation path, model, view or controller folder path
3) the public information of the website, such as the name of the website, keywords and so on.
16. What are the advantages of functions?
Improve the maintainability of the program, improve the reliability of the software, improve the reusability of the program, improve the development efficiency of the program.
17. How do you define a function? Are function names case sensitive?
1) use the function keyword
2) function naming rules are the same as variables, starting with a letter or underscore, but not with a number
3) function names are not case-sensitive
4) function names cannot use function names that have been declared or built by the system.
18. What is the visibility or scope of variables?
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 global variables be called directly within the function?
A local variable is a variable defined within a function, and its scope is the function in which it is located. If there is a variable with the same name as the local variable outside the function, the program will think that they are two completely different variables. When you exit the function, the local variables are cleared at the same time. Global variables are variables defined outside all functions, and their scope is the entire php file, but cannot be used inside user-defined functions. If you must use global variables inside a user-defined function, you need to declare it using the global keyword. In other words, if the variable in the function is decorated with golbal, then the global variable can be accessed inside the function, not only the global variable can be used for operation, but also the global variable can be reassigned. Global variables can also be called using $GLOBALS ['var'].
21. What are static variables?
If a variable defined within a function is declared before the keyword static, then the variable is static.
General variables in the function after the end of the function call, its stored data will be cleared, the memory space will also be released. When using a static variable, the variable will be initialized when the function is called for the first time, and will not be cleared after initialization. When the function is called again, the static variable will no longer be initialized, but the value after the last function execution can be saved. It can be said that static variables are shared among all calls to the function.
twenty-two。 What are the ways in which functions pass parameters in php? What's the difference between the two?
Pass by value and by address (or by reference)
(1) pass by value: the variable to be passed is stored in a different space from the variable passed to the function. So the function body is right
The modification of the value of this variable does not affect the original value of the variable.
(2) pass by address: use the & symbol to indicate that the parameter is passed as an address. Instead of passing the specified value or target variable in the main program to the function, the address of the memory storage block of the value or variable is imported into the function, so the variable in the function is the same in memory as the variable in the main program. 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 you call yourself, it must be closer to the final result
2) there must be a definite recursive termination condition, which will not cause an endless loop.
Examples are as follows:
In practice, it is often used when traversing folders.
If there is an example where you want to get all the files under the directory windows, then first iterate through the windows directory, and if you find that there are folders in it, you will call yourself and continue to look for it, and so on.
Until there are no more folders, which means that all the files are traversed.
24. Determine whether a function exists or not?
Function_exists (string $function_name) returns true if it exists, or false if it doesn't exist.
25. What's the difference between func () and @ func ()?
The failure of the second function call will not report an error, and the first will report an error
twenty-six。 What are the uses and differences between the include () and require () functions? What about include_once () and require_once ()?
Include and require have different error levels after errors.
Include_once () and require_once () determine whether they have been imported before loading.
twenty-seven。 Tell the difference between front + and post +?
The prefix + + first increases the variable by 1, and then assigns the value to the original variable.
The post + + first returns the current value of the variable, and then increases the current value of the variable by 1.
twenty-eight。 String operator "." What's the difference from the arithmetic operator "+"?
When used between "a" and "b". It is considered to be a hyphen. If there is a + between the two, php will think of it as an operation.
1) if the string on both sides of the + sign is made up of numbers, the string will be automatically converted to an integer
2) if there are pure letters on both sides of the + sign, 0 will be output.
3) if the string on both sides of the + sign begins with a number, the number at the beginning of the string is intercepted and the operation is performed.
twenty-nine。 What is a ternary (or ternary) operator?
Select one of the other two expressions based on the result of one expression.
For example: ($a==true)? 'good':'bad'
thirty。 What are the control flow statements?
1: three kinds of program structures: sequence structure, branch structure and loop structure
2: branch: if/esle/esleif/ switch/case/default
3: switch needs to pay attention to:
Constants in the case clause can be integers, string constants, or constant expressions, and are not allowed to be variables.
The value of case cannot be the same in the same switch clause, otherwise you can only get the value in the first occurrence of case.
4: cyclic for while do...while
A semicolon must be added after the do...while.
The difference between while and do...while
The difference between 5:break and continue.
Break can terminate the loop.
Continue is not as powerful as break, so it can only stop this cycle and move on to the next.
thirty-one。 What is the concept of array? Which two kinds of arrays are divided according to the index and how to distinguish them? What are 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 a number, starting with 0) and associative array (with string as index value)
What are 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 the index and value by key= > value, or you can give only the element value of the array without defining the index subscript of the array.
two。 Assign values to array elements directly without calling the array () function. For example:
$arr [0] = 1; $arr [1] = 2
Pay special attention to:
If the subscript of an array is equivalent to the string value of an integer (but cannot start with 0), it is treated as an integer.
For example, $array [3] and $array ['3'] refer to the same element, while $array ['03'] refers to another element.
thirty-two。 How to traverse the array?
① for cycle
② foreach loop, which is the most commonly used traversal method. Usage: foreach ($arr as $key= > $value) {}
③ list each and while work together to cycle
thirty-three。 How does the pointer point to the foeach array?
How does the pointer point when list () / each () / while () loops the array?
When foreach starts execution, the pointer inside the array automatically points to the first unit. Because foreach operates on a copy of the specified array, not the array itself. After each () an array, the array pointer stays at the next cell in the array or at the end of the array. If you want to use each () to traverse the array again, you must use reset ().
Reset () reverses the inner pointer of the array back to the first cell and returns the value of the first array cell.
thirty-four。 How to calculate the length of an array (or the number of all elements in the array)? How to take the length of a string?
Count ()-counts the number of elements in the array.
You can use count (array name) or count (array name, 1), which, if there is a second parameter and is the number 1, represents the number of elements in the array recursively. If the second argument is the number 0, it is equivalent to the count () function with only one argument.
Sizeof ()-- alias for count () (count-counts the number of elements in an array or the number of attributes in an object)
String: strlen ()-gets the length of the string
Mb_strlen ()-Get string length
thirty-five。 What are the related common functions in the array?
1) count-(sizeof alias)-calculates the number of elements in the array or the number of attributes in the 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 of $mode is 0. 1 to turn on recursively counting the array
2) in_array (mixed $needle, array $haystack [, bool $strict])-checks whether a value exists in the array. If needle is a string, the comparison is case-sensitive. If the value of the third parameter, strict, is TRUE, the in_array () function also checks to see if the type of needle is the same as in haystack.
3) array_merge (array $array1 [, array $array2 [, array $...]]) merges the cells of one or more arrays, and the values in one array are appended to the previous array. Returns an array as a result.
Special note: if you enter an array with the same string key name, the value after that key name will overwrite the previous value. However, if the array contains numeric key names, the subsequent values will not overwrite the original values, but will be appended to them.
If only one array is given and the array is numerically indexed, the key name is re-indexed in a continuous manner
4) conversion between array and string
(1) explode (string $separator, string $string [, int $limit]) uses a delimiter to separate a string.
(2) implode (string $glue, array $arr) uses a connector to concatenate each unit in the array into a string. Join is an alias for implode
5) sort (array & $array [, int $sort_flags])-sorts the array by value, and the array cells will be rearranged from the lowest to the highest at the end of this function.
thirty-six。 What is the difference between the number combination union function array_merge () and the array addition operation $arr + $arr2?
Array_merge ()-> use array_merge (). If it is an associative array merge, if the key name of the array is the same, then the latter value will overwrite the former; if it is a numerically indexed array merge, it will not be overwritten, but the latter will be appended to the former. " + "- > uses the array addition operation, which, unlike array_merge (), discards the value of the same key name, whether it is an associative array or a numerically indexed array, that is, only the elements that appear the key name for the first time, and subsequent elements with the same key name will not be added.
thirty-seven。 What is the difference between single quotation marks and double quotation marks when defining a string?
The loading speed of single quotation mark is faster than that of double quote.
thirty-eight。 What is the difference between echo (), print () and print_r ()?
(1) echo is syntax, Output one or more strings, and no return value is returned.
(2) print is a function and cannot 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, etc., output array will be expressed in structure, print_r output success returns true; and print_r can be through print_r ($str,true), so that print_r does not output and return the value after print_r processing. In addition, for echo and print, echo is mostly used because it is more efficient than print.
thirty-nine。 What are the string handling functions according to the functional classification? What are the functions of these functions?
a. String output function
(1) echo $a language structure, not a real function, is a language structure.
(2) print ($a) this function outputs a string. Return 1 for success and 0 for failure
(3) print_r ($a)
(4) var_dump ($a); can output type, length, and value
b. The function that removes the leading and trailing spaces of a string: trim ltrim rtrim (alias: chop) takes the second argument and also removes the specified characters.
c. Escape string function: addslashes ()
d. Function to get the length of a string: strlen ()
e. A function that intercepts the length of a string: substr ()
f. Retrieve string functions: strstr (), strpos ()
g. Replace string function: str_replace ()
forty。 Please give the correct answers to the following questions?
1). $arr = array ('james',' tom', 'symfony'); please split and merge the value of the $arr array with', 'into a string output? Echo implode (',', $arr)
2). $str = 'jack,james,tom,symfony'; Please split $str with', 'and put the split value in the $arr array? $arr = explode (',', $str)
3). $arr = array; please sort $arr in order from largest to smallest and keep its key value unchanged? Arsort ($arr); print_r ($arr)
4). $mail = "gaofei@163.com". Please take out the 163.com of this mailbox and print it. How many ways can you write?
Echo strstr ($mail,'163')
Echo substr ($mail,7)
$arr = explode ("@", $mail); echo $arr [1]
5)。 If there is a string, the string is "123jin234pd345,". Could you tell me how to cut the last comma of this string?
6)。 How many functions are there to get random numbers? Which is faster, mt_rand () or rand ()?
forty-one。 The page character appears garbled, how to solve?
1. First consider whether the current file has a character set. Check to see if charset is written in the meta tag, and if it is a php page, you can also see if it is.
Charset is specified in the header () function
For example:
Header ("content-type:text/html;charset=utf-8")
two。 If the character set (that is, charset) is set, it is determined whether the encoding format saved in the current file is consistent with the character set set on the page.
The two must remain unified.
3. If it involves extracting data from the database, it must be unified to determine 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").
forty-two。 What is a regular expression? What are the commonly used regularization-related functions in php? Please write a regular expression of email, Chinese mobile phone number and landline number?
A regular expression is a grammatical rule used to describe the arrangement pattern of characters. Regular expressions are also called pattern expressions.
In website development, regular expressions are most commonly used for client-side validation before a form submits information.
For example, verify whether the user name is entered correctly, whether the password input meets the requirements, and whether the input of email, mobile phone number and other information is legal.
In php, regular expressions are mainly used for string segmentation, matching, finding and replacing operations.
Preg series functions can be handled. The details are as follows:
String preg_quote (string str [, string delimiter])
Special characters that escape regular expression characters include:. \ + *? [^] $() {} =!
< >|:.
Preg_replace-perform search and replacement of regular expressions
Mixed preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit]
Preg_replace_callback-search and replace regular expressions with callback functions
Mixed preg_replace_callback (mixed pattern, callback callback, mixed subject [, int limit])
Preg_split-- splits strings with regular expressions
Array preg_split (string pattern, string subject [, int limit [, int flags]])
Common regular expressions are written:
English: / ^ [\ u4E00 -\ u9FA5] + $/
Mobile phone number: / ^ (86)? 031\ d {10} $/
EMAIL:
/ ^ [\ w -] + [\ w house.]? @ [\ w -] +\. {1} [A-Za-z] {2jue 5} $/
Password (in security level):
/ ^ (\ d + [A-Za-z]\ w* | [A-Za-z] +\ d\ w*) $/
Password (high security level):
/ ^ (\ d + [a-zamurZhenzhouxiaoyue% ^ & () {}]] [\ wishi Zaoyun% ^ & () {}] * | [aMuzAashi / Zaoyuzhuangyuzhuo% ^ & () {}] +\ d [\ washi Zaoyangzhouqian% ^ & () {}] *) $/
forty-four。 What is the difference between the use of the preg_replace () and str_ireplace () functions? How are the preg_split () and split () functions used?
Preg_replace-performs search and replacement of regular expressions
Ignore case version of str_ireplace-str_replace () str_replace-substring replacement
Preg_split-splits strings with regular expressions
Split-splits a string into an array with regular expressions
forty-five。 What are the main functions to get the current timestamp? Print out today's time in PHP in the format of 2010-12-10 22:21:21?
Print out in PHP the time format of the previous day is 2010-12-10 22:21:21? How do I change 2010-12-25 10:30:25 into a unix timestamp?
Echo date ("Y-m-d H:i:s", strtotime ('- 1memdays'))
Date ('Y-m-d haze, iRu, fuzz, etc.)
$unix_time = strtotime ("2009-9-2 10:30:25"); / / becomes a unix timestamp
Echo date ("Y-m-d H:i:s", $unix_time); / / formatted to normal time format
forty-six。 When using get to pass values in url, if there is garbled code in Chinese, which function should be used to encode the Chinese?
When a user submits data on a form on a website, in order to prevent scripting attacks (such as user input alert), what should the PHP side do when it receives the data?
Use urlencode () to encode the Chinese language and urldecode () to decode it.
Scripting attacks can be avoided by using htmlspecialchars ($_ POST ['title']) to filter form pass parameters.
forty-eight。 What's the difference between MySQL _ fetch_row () and mysql_fetch_assoc () and mysql_fetch_array?
The first returns a row in the result set as an indexed array, the second returns an associative array, and the third returns either an indexed array or an associative array, depending on its second parameter, MYSQL_BOTH MYSQL_NUM MYSQL_ASSOC, which defaults to MYSQL_BOTH
$sql = "select * from table1"
$result = mysql_query ($sql)
Mysql_fetch_array ($result, MYSQL_NUM)
forty-nine。 Please say that what you have learned so far is a function of the resource?
Answer: fopen (Open File)
Imagecreatefromjpeg (png gif)-create a new image from the JPEG file
Imagecreatetruecolor-create a new true color image
Imagecopymerge-copy and merge parts of the image
Imagecopyresized-copy and resize part of the image
Mysql_connect-Open a connection to the MySQL server
Mysql_query (); only if the select executes successfully, the resource will be returned, and the failure will return FALSE.
fifty。 What are the functions of opening and closing files? What is the function of reading and writing files? Which function is to delete a file?
Which function is it to determine whether a file exists? Which function is the new directory?
fifty-one。 What details should I pay attention to when uploading files? How to save the file to the specified directory? How to avoid the problem of uploading files with duplicate names?
1. First of all, you need to enable file upload in php.ini.
two。 There is a maximum allowed upload in php.ini, and the default is 2MB. Can be changed if necessary
3. When uploading a form, remember to write enctype= "multipart/form-data" in the form tag.
4. Submission method method must be post
5. Set the form controls for type= "file"
6. You should pay attention to whether the size MAX_FILE_SIZE and file type of the uploaded file meet the requirements, and whether the path to be stored after uploading exists.
You can get the file suffix from the uploaded file name, and then rename the file using a timestamp + file suffix, thus avoiding duplicate names. You can set up the save directory of the uploaded file, piece together a file path with the file name, and use move_uploaded_file () to save the file to the specified directory.
fifty-two。 What dimensional array is $_ FILES? What are the index subscripts for the first and second dimensions, respectively? What should I pay attention to 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.
fifty-three。 What are the main functions of the header () function? What do you pay attention to in the process of use?
A:
Header () sends http header information
-header ("content-type:text/html; charset=utf-8");-/ / the output of the current page is html and encoded in utf-8 format
-
-header ("content-type:image/png gif jpeg");-- / / the output of the current page is in the format of pictures.
-header ("refresh:5;url= http://www.1004javag.com/five/string.php");--// page will jump to the new URL in 5 seconds
-header ("location: http://1004javag.com/five/string.php");-----------// page redirection
fifty-four。 What if I use the header () function when downloading the file?
Answer: header ("content-type: application/octet-stream;charset=UTF-8"); / / what's the difference between adding utf-8 here and defining it above? 、??
Header ("accept-ranges: bytes")
Header ("accept-length:" .filesize ($filedir.$filename))
Header ("content-disposition: attachment; filename=". $filedir.$filename)
fifty-five。 What is ajax? What is the principle of ajax? What is the core technology of ajax? What are the advantages and disadvantages of ajax?
Ajax is the abbreviation of asynchronous javascript and xml, which is the combination of javascript, xml, css, DOM and other technologies. '$' is an alias for jQuery.
The user's request on the page communicates with the server asynchronously through the ajax engine, and the server returns the result of the request to the ajax engine.
Finally, it is up to the ajax engine to decide to display the returned data to the specified location on the page. Ajax finally makes it possible to load all the output of another page at a specified location on another page.
In this way, a static page can also get the returned data information in the database. So ajax technology enables a static web page to communicate with the server without refreshing the entire page.
It reduces the user waiting time, reduces the network traffic, and enhances the friendliness of the customer experience.
The advantages of Ajax are:
1. It reduces the burden on the server, transfers part of the work previously borne by the server to the client for execution, and uses the idle resources of the client to deal with it.
two。 Update the page in the case of only a local refresh, which increases the response speed of the page and makes the user experience more friendly.
The disadvantage of Ajax is that it is not conducive to seo promotion and optimization, because search engines cannot directly access the content requested by ajax.
The core technology of ajax is XMLHttpRequest, which is an object in javascript.
fifty-six。 What is jquery? What are the ways in which jquery simplifies ajax?
JQuery is a framework of Javascript.
$.get (), $.post (), $.ajax (). $is an alias for the jQuery object.
The code is as follows:
$.post (url address of asynchronous access, {'parameter name': parameter value}, function (msg) {
$("# result") .html (msg)
});
$.get (url address of 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)
}
});
fifty-seven。 What is session control?
To put it simply, session control is a mechanism for tracking and identifying user information. The idea of session control is to be able to track a variable in the website. through this variable, the system can identify the corresponding user information and know the user rights according to this user information. in order to show users the page content suitable for their corresponding permissions. At present, the most important session tracking method is cookie,session.
fifty-eight。 Basic steps for session tracking
1). Access the session object associated with the current request 2). Find information related to the session
3). Store session information 4). Discard session data
fifty-nine。 What are the considerations for using cookie?
1) No page output is allowed before setcookie (), even spaces and blank lines are not allowed.
2) after setcookie (), calling $_ COOKIE ['cookiename'] on the current page will have no output. You must refresh or go to the next page to see the cookie value.
3) different browsers deal with cookie differently. Clients can disable cookie, and browsers can idle the number of cookie. A browser can create up to 300 cookie, and each cannot exceed 4kb.
The total number of cookie that can be set per web site cannot exceed 20.
4) cookie is saved on the client side, and the user disables cookie, so setcookie will not work. So you can't rely too much on cookie.
sixty。 When using session, what does it use to represent the current user, thus distinguishing it from other users?
Sessionid, the current session_id can be obtained through the session_id () function.
sixty-one。 What are the steps for using session and cookie, respectively? What is the life cycle of sesssion and cookie? What is the difference between session and cookie?
Cookie is saved on the client machine. For cookie with no expiration time set, the cookie value is saved in the machine's memory, and the cookie disappears automatically as soon as you close the browser. If the expiration time of cookie is set, the browser saves the cookie to the hard disk as a text file, and the cookie value is still valid when the browser is opened again.
Session is to save the information that users need to store on the server side. The session information of each user is stored on the server side like a key-value pair, where the key is sessionid, and the value is the information that the user needs to store. The server uses sessionid to distinguish which user belongs to the stored session information.
The biggest difference between the two is that session is stored on the server side, while cookie is stored on the client side. Session is more secure than cookie.
Session plays a very important role in web development. It can record the information of the user after logging in correctly to the memory of the server, and when the user accesses the administrative background of the website under this identity, he can get the identity confirmation without logging in again. Users who do not log in correctly do not allocate session space and cannot see the content of the page even if they enter the access address of the administrative background. The user's right to operate on the page is determined by session.
To use session:
1. Start session: use the session_start () function to start.
two。 Registration session: simply add elements to the $_ SESSION array.
3. Use session: determine whether the session is empty or registered, and if it already exists, it can be used like a normal array.
4. Delete a session:
1. You can delete a single session using unset
two。 Use $_ SESSION=array () to log out all session variables at once
3. Use the session_destroy () function to completely destroy session.
How to use cookie?
1. Record some of the information accessed by the user
two。 Pass variables between pages
3. Storing the viewed internet pages in a temporary cookies folder can improve the browsing speed in the future.
Create cookie:setcookie (string cookiename, string value, int expire)
Read cookie: read the value of cookie on the browser side through the super global array $_ COOKIE.
Delete cookie: there are two ways
1. Manual deletion method:
Right-click on the browser properties, you can see delete cookies, perform the action to delete all cookie files.
2.setcookie () method:
This is the same as setting cookie, except that the value of cookie is set to empty and the valid time is 0 or less than the current timestamp.
sixty-two。 How do I set the name of a cookie to username, the value to jack, and invalidate the cookie after a week?
How many cookie can be generated by a browser and how many cookie files can be generated?
Setcookie ('username','jack',time () + 7 / 24 / 3600)
A maximum of 20 cookie can be generated, each with a maximum of 4K
sixty-three。 What do I need to do before setting up or reading session?
You can open session.auto_start = 1 directly in php.ini or use session_start () in the header of the page.
You cannot have any output, including blank lines, before turning on session,session_start ().
sixty-four。 Where is session used in actual development?
Session is used to store user login information and to pass values across pages.
1) it is common to assign user login information to session after the user has successfully logged in
2) it is used for verification code picture generation, and when the random code is generated, it is assigned to session.
sixty-five。 What are the forms of logging out of a session session?
Unset () $_ SESSION=array (); session_destroy ()
sixty-six。 What is OOP? What are classes and objects? What are class attributes?
OOP (object oriented programming), that is, object-oriented programming, in which the two most important concepts are classes and objects.
All things in the world have their own properties and methods, through which different substances can be distinguished.
The collection of attributes and methods forms the class, which is the core and foundation of object-oriented programming.
Through classes, the fragmented code used to implement a function is effectively managed.
The class is just an abstract model with some functions and attributes, but in practical application, an entity is needed, that is, the class needs to be instantiated, and the class is the object after instantiation. The ★ class is the abstract concept of the object, and the object is the instantiation of the class.
The object is an advanced array, the array is the most primitive object, and the same object can be traversed.
OOP has three main characteristics:
1. Encapsulation: also known as information hiding, is to separate the use and implementation of a class, leaving only some interfaces and methods in contact with the outside world, or exposing only some methods for developers to use. So developers only need to pay attention to how to use this class, but not to care about its specific implementation process, so that we can achieve MVC division of labor, but also effectively avoid interdependence between programs, and achieve loose coupling between code modules.
two。 Inheritance: a subclass automatically inherits properties and methods in its parent class, and can add new properties and methods or override some properties and methods. Inheritance increases code reusability. Php only supports single inheritance, which means that a subclass can only have one parent class.
3. Polymorphism: the subclass inherits properties and methods from the parent class and overrides some of the methods. So although multiple subclasses have the same method, but the objects instantiated by these subclasses can get completely different results after calling these same methods, this technique is polymorphism. Polymorphism enhances the flexibility of the software.
Advantages of OOP: 1, high code reusability (save code) 2, high maintainability of the program (expansibility) 3, flexibility
sixty-seven。 What are the commonly used access modifiers for properties? What do they stand for?
Private,protected,public .
Out of class: public, var
In subclasses: public,protected, var
In this class: private,protected,public, var
If you don't use these three keywords, you can also use the var keyword. However, var cannot be used with permission modifiers. Variables defined by var can be accessed in subclasses or outside classes, which is equivalent to public
Class: only final,abstract can be added
Property: there must be an access modifier (private,protected,public,var)
Front of the method: static,final,private,protected,public, abstract
sixty-eight。 What do the three keywords $this and self and parent stand for respectively? On what occasions do you use it?
$this current object self current class parent the parent of the current class
$this is used in the current class, using-> to call properties and methods.
Self is also used in the current class, but you need to use:: call. Parent is used in classes.
sixty-nine。 How to define constants in a class, how to call constants in a class, and how to call constants outside a class.
A constant in a class is a member constant, and a constant is a constant that does not change.
Define the constant using the keyword const.
For example: const PI = 3.1415326
Whether in-class or out-of-class, constant access is different from variables, and constants do not need to instantiate objects.
The format of the access constant is called by the class name plus the scope operation symbol (double colon).
That is: class name:: class constant name
seventy。 Scope operator:: how to use it? On what occasions are they used?
Call class constant call static method
seventy-one。 What is magic? What are the common magic methods?
A system-customized method that starts with _ _.
_ _ construct () _ _ destruct () _ _ autoload () _ _ call () _ tostring ()
seventy-two。 What are construction methods and destructions?
A constructor is a member method that executes automatically when an object is instantiated, and its function is to initialize the object.
Before php5, a method that is exactly the same as the class name is the constructor, and after php5, the magic method _ _ construct () is the constructor. If there is no constructor defined in the class, php automatically generates one, which has no parameters or operations.
The format of the constructor is as follows:
Function _ _ construct () {}
Or: function class name () {}
The constructor can have no parameters, or it can have multiple parameters.
The function of the destructor is the opposite of the constructor, which is called automatically when the object is destroyed, and the function is to release memory.
The definition method of destructing method is: _ _ destruct ()
Because php has a garbage collection mechanism, it can automatically clean up objects that are no longer in use and free up memory. In general, you can not create destructors manually.
seventy-three。 How does the _ _ autoload () method work?
The basic condition for using this magic function is that the file name of the class file is the same as the name of the class.
When the program executes to instantiate a class, if the class file is not introduced before instantiation, the _ _ autoload () function is executed automatically. This function will find the path of the class file based on the name of the instantiated class. When it is determined that the class file does exist under the class file path, execute include or require to load the class, and then the program continues to execute, if the file does not exist under this path.
It prompts you for an error. Using automatically loaded magic functions, you don't have to write many include or require functions.
seventy-four。 What are abstract classes and interfaces? What are the differences and similarities between abstract classes and interfaces?
An abstract class is a class that cannot be instantiated and can only be used as a parent class of other classes.
Abstract classes are declared by the keyword abstract.
An abstract class is similar to an ordinary class in that it contains member variables and member methods. The difference between the two is that an abstract class contains at least one abstract method.
An abstract method has no method body, and the method is inherently overridden by subclasses.
The format of the abstract method is: abstract function abstractMethod ()
Because only single inheritance is supported in php, you need to use interfaces if you want to implement multiple inheritance. That is, subclasses can implement multiple interfaces. The interface class is declared by the interface keyword, the member variables and methods in the interface class are public, the method can not write the keyword public, and the method in the interface has no method body. The methods in the interface are also inherently implemented by subclasses. The functions of abstract classes and interfaces are very similar, but the biggest difference is that interfaces can implement multiple inheritance. The choice of abstract class or interface in the application depends on the specific implementation. The subclass inherits the abstract class using extends, and the subclass implementation interface uses 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 methods in it
If there are abstract methods in a class, the class must be abstract
seventy-five。 How many parameters are there for _ _ call, what is the type, and what is the meaning?
The purpose of 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 method that does not exist.
_ _ call () contains two parameters, the first of which is the method name of the method that does not exist, which is a string type
The second parameter, which is an array type, is all the parameters of the method that does not exist.
I think the meaning of the _ _ call () method is more about debugging, which can locate the error. At the same time, exceptions can be caught, and if a method does not exist, other alternatives can be performed.
seventy-six。 What is the purpose of smarty template technology?
In order to separate php from html, artists and programmers do their own jobs and do not interfere with each other.
seventy-seven。 What are the main smarty configurations?
1. Introduction of smarty.class.php
two。 Instantiate smarty object
3. Modify the default template path again
4. Re-modify the default path of the compiled file
5. Re-modify the path of the default profile
6. Modify the path of the default cache again.
7. You can set whether cache is enabled or not.
8. You can set the left and right delimiters.
seventy-eight。 What details do you need to pay attention to when using smarty?
Smarty is a template engine based on the concept of MVC, which divides a page program into two parts: the view layer and the control layer, that is to say, smarty technology separates the user UI from the php code. In this way, programmers and artists do their own jobs and do not interfere with each other.
The following problems should be paid attention to in the application of smarty:
1. Configure smarty correctly. The main thing is to instantiate the smarty object and configure the path of the smarty template file
Use assign assignment and display to display pages in 2.php pages
Php code snippets are not allowed in 3.smarty template files. All comments, variables, and functions should be included in delimiters.
A. {}
B. Foreach
C. If else
D. Include
E. Literal
seventy-nine。 What is the concept of MVC? What is the main work done on each floor?
MVC (Model-View-Controller) is a kind of software design pattern or programming idea.
M refers to the Model 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 achieve the separation of M and V, so that a program can easily use different user interfaces.
In the development of the website
The model layer is generally responsible for adding, deleting, modifying and querying the database table information.
The view layer is responsible for displaying the page content.
The controller layer acts as a moderator between M and V, and the controller layer decides which method of which model class is called.
After execution, it is up to the controller layer to decide which view layer to assign the result to.
eighty-one。 What does method rewriting and overloading mean in the java language? Does php precisely support method overloading? How to understand the php overloading mentioned in many reference books correctly?
A:
Php does not support method overloading, and PHP' overloading mentioned in many books should be 'rewritten'.
eighty-two。 Can the final keyword define member properties in a class?
Answer: no, the member attributes of a class can only be defined by public, private, protected, and var
eighty-three。 Can classes defined by the final keyword be inherited?
Answer: classes defined by final cannot be inherited
eighty-four。 Tell me where to use the static keyword? Can static be used before class?
Can static be used with public,protected,private? Can the constructor be static?
Answer: static can be used in front of properties and methods. When calling static properties or methods, you can simply load the class without instantiating it.
Static cannot be used in front of class
Static can be used with public,protected,private, in front of the method
▲ constructor cannot be static
eighty-five。 Can the interface be instantiated? Can abstract classes be instantiated?
Answer: neither interface nor abstract class can be instantiated
eighty-six。 Can I add an access modifier before class? If it can be added, which access modifiers can only be? Can it be the permission access modifier public,protected,private?
Answer: you can add final,static before class
★ class cannot be preceded by public,protected,private
eighty-seven。 Can there be no access modifiers before the properties in the class? Can the modifier before a member variable only be public,protected,private? What else could it be?
A: the attributes in the class must be modified. In addition to those three, you can also add var.
eighty-eight。 If you echo an array, what does the page output? Echo, what about an object? Print an array or an object?
Answer: the page can only output "Array"; echo an object will appear "Catchable fatal error: Object of class T2 could not be converted to string in G:\ php2\ t2.php on line 33"
Print an array only outputs "Array", print an object appears "Catchable fatal error: Object of class T2 could not be converted to string in G:\ php2\ t2.php"
▲ print and echo are the same.
eighty-nine。 When is the _ _ tostring () magic method performed automatically?
Does the _ _ tostring () magic method have to have a return return value?
When echo or print an object, it is automatically triggered. And _ _ tostring () must return a value
ninety。 What is an abstract method?
A: there is an abstract in front of the method, and the method does not have a method body, not even "{}"
ninety-one。 If a method in a class is an abstract method and the class is not defined as an abstract class, will an error be reported?
Yes, "Fatal error: Class T2 contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (t2::ee) in"
ninety-two。 If a class is abstract, and the methods in the class are all non-abstract methods, will an error be reported?
Answer: no error will be reported. If a class is an abstract class, there can be no abstract method, but a method in a class is an abstract method, then the class must be an abstract class.
ninety-four。 What should be paid attention to in the application of final keyword?
Classes defined with the final keyword, inheritance is prohibited.
Overrides are prohibited by methods defined using the final keyword.
ninety-five。 What if a class inherits a parent class and implements multiple interfaces?
Writing format such as: class MaleHuman extends Human implements Animal,Life {...}
ninety-six。 What is a single point entrance?
The so-called single entry means that the entire application has only one entry, and all implementations are forwarded through this entry.
For example, in the above we use index.php as a single point of entry to the program, of course, this can be controlled by yourself.
There are several benefits of a single point entrance:
First, some variables, classes, and methods that the system handles globally can be handled here. For example, you need to initially filter the data, you have to simulate session processing, you have to define some global variables, and you even have to register some objects or variables into the registry.
Second, the structure of the program is clearer.
ninety-seven。 PHP provides two sets of regular expression function libraries. Which two sets are they?
(1) PCRE Perl compatible regular expression preg_ is prefixed
(2) POSIX portable operating system interface ereg_ is prefixed.
ninety-eight。 What is the composition of regular expressions?
By atoms (ordinary characters, such as English characters),
Metacharacters (characters with special functions)
Pattern correction character
A regular expression contains at least one atom
ninety-nine。 What is the trigger time when magic is not often used?
Trigger time of _ _ isset () _ unset ()
_ _ sleep (), _ _ wakeup () are called when the object is serialized
If the _ _ sleep () method is not written when serializing the object, all member properties are serialized, while the _ _ sleep () method is defined, only the variables in the specified array are serialized. Therefore, this function is also useful if you have very large objects that do not need to be completely stored.
The purpose of using _ _ sleep is to close any database connections that objects may have, submit waiting data, or perform similar cleanup tasks. In addition, this function is useful if you have very large objects that do not need to be fully stored.
The purpose of using _ _ wakeup is to rebuild any database connections that may be lost during serialization and to handle other reinitialization tasks.
The above is all the content of this article "what is the Common knowledge of PHP/Javascript/CSS/jQuery?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.