Compiled a list of interview questions for recruiting PHP senior engineers, PHP senior engineers
1. Basic knowledge points
. . .
The difference between Include require include_once require_once.
The evolutionary history of several versions of PHP/Mysql, such as major improvements from mysql4.0 to 4.1, PHP 4.x to 5.1, etc.
Php code
- MySQL:
-
- 1. Main changes from 4.0 to 4.1
-
- If an InnoDB table containing a TIMESTAMP field was created in MySQL versions 4.1.0 to 4.1.3. Then you need to rebuild the table when upgrading to 4.1.4 and higher because the storage format has changed.
-
- Strings are compared according to standard SQL: trailing spaces are not removed before comparison, and shorter strings were previously extended with trailing spaces. The current result is
-
- 'a' > 'at', this was not the case before. You can use mysqlcheck to check the data table.
-
- TIMESTAMP returns a string in the format of 'YYYY-MM-DD HH:MM:SS'. In MySQL 4.0, you can add the option --new to get this feature in ySQL 4.1.
-
- Before MySQL 4.1.1, the statement parser was not so strict. It would ignore other characters before the first number when processing string to time conversion. After 4.1.1, it is more strict. The result of a function whose return result is DATE, DATETIME, or TIME type will be converted into time type
-
- 2. Let’s look at the main changes from 4.1 to 5.0
-
- ◆The index order of TEXT fields ending in spaces in InnoDB and MyISAM tables has changed. Therefore, you need to run the "CHECK TABLE" statement to repair the data table. If an error occurs, run the "OPTIMIZE TABLE" or "REPAIR TABLE" statement to repair it, or even re-dump it (using mysqldump).
-
- ◆Starting from MySQL 5.0.15, how to handle the value filled in the BINARY field has changed. The padded value is now 0x00 instead of spaces, and the trailing spaces will not be removed when retrieving the value.
-
- ◆Starting from MySQL 5.0.3, the implementation of DECIMAL has changed. 5.0 has much stricter format restrictions on DECIMAL. DECIMAL fields created in MyISAM and InnoDB tables between MySQL 5.0.3 and 5.0.5 will crash after upgrading to 5.0.6. Starting with 5.0.3, DECIMAL is stored in a more efficient format. Starting in 5.0.3, exact math is used when calculating DECIMAL values and rounding exact values.
-
- ◆In the past, waiting for a timeout lock would cause InnoDB to roll back all current transactions. Starting from 5.0.13, only the most recent SQL statement will be rolled back.
-
- ◆Before 4.1.13/5.0.8, DATETIME was converted into YYYYMMDDHHMMSS format after adding 0, and now it is in YYYYMMDDHHMMSS.000000 format
-
- ◆In 4.1, the comparison between FLOAT or DOUBLE happens to be fine, but it may not work in 5.0
-
- ◆ Starting from 5.0.3, the spaces at the end of VARCHAR and VARBINARY fields are no longer deleted
-
- ◆ Added a new startup option innodb_table_locks, which causes InnoDB table locks to be requested when LOCK TABLE. This option is enabled by default, but may cause deadlock in AUTOCOMMIT=1 and LOCK TABLES applications. It seems that I only need to focus on the two types of changes: time (TIMESTAMP, DATETIMEDATE, TIME) and numeric type (FLOAD, DOUBLE, DECIMAL); in addition, I do not need to involve it in the upgrade process yet. Character set issues, so it's relatively easy.
-
- Upgrade steps are as follows:
-
- Execute
-
- FLUSH TABLES WITH READ LOCK;
-
- Directly copy the MyISAM table file
-
- Use mysqldump to export Innodb type tables
-
- The whole process went smoothly. After the new system was started, the following 2 problems were discovered:
-
- The keyword INOUT has been added, so you need to check what other fields in the table structure use the keyword
-
- DATE_FORMAT function has much stricter requirements,
-
- DATE_FORMAT('2006/11/24 09:14:00', '%Y-%m-%d %T')
- and DATE_FORMAT('2006/11/2409:14:00', '%Y-%m-%d %T')
-
The results of - are completely different. In 4.0, these two formats are compatible, but in 5.0, you can only use the former correctly, and the latter will have problems. This should also be caused by the change in time type mentioned above.
PHP:
Php code
- The following improvements in PHP5 are worthy of attention:
- 1. Greatly improved object-oriented capabilities;
- 2. Support try/catch exception handling;
- 3. Improved string processing;
- 4. Improved xml and web service support;
- 5. Built-in support for SQlite.
HEREDOC introduction
Php code
- Heredoc technology is generally not described in detail in formal PHP documents and technical books. It is only mentioned that it is a Perl-style string output technology. However, some current forum programs and some article systems cleverly use heredoc technology to partially realize the quasi-separation of interface and code. The phpwind template is a typical example.
-
- 1. Start with the End start tag and end with the End end tag. The end tag must be written at the top, without indentation or spaces, and there must be a break at the end of the end tag. Number . The start tag is the same as the start tag. For example, it is commonly represented by capital letters EOT, EOD, and EOF, but it is not limited to those few. Just make sure that the start tag and the end tag do not appear in the text.
-
- 2. Variables located between the start tag and the end tag can be parsed normally, but functions cannot. In heredoc, variables do not need to be spliced with connectors. or,, as follows:
-
- $v=2;
- $a=
- "abc"$v
- "123"
- EOF;
- echo $a;
-
- 3. heredoc is often used when outputting documents containing a large number of HTML syntax. For example: the function outputhtml() should output the HTML home page. There are two ways to write it. Obviously the second way of writing is simpler and easier to read.
-
- function outputhtml(){
- echo "";
- echo "Homepage";
- echo "Homepage content";
- echo ";
- }
-
- function outputhtml()
- {
- echo
-
- Homepage
- Homepage content
-
- EOT;
- }
-
- outputhtml();
-
- The $ variable will be automatically replaced in heredoc, and the command and input will be put together for convenience
Write some php magic methods;
Php code
- PHP stipulates that methods starting with two underscores (__) are reserved as magic methods, so it is recommended that your function name should not start with __ unless it is to overload an existing magic method.
- The magic methods in PHP are: __construct, __destruct, __call, __callStatic,__get, __set, __isset, __unset, __sleep, __wakeup, __toString, __set_state, __clone, __autoload
- 1, __get, __set
- These two methods are designed for properties that are not declared in the class and their parent class
- __get( $property ) This method will be triggered when an undefined property is called, and the parameter passed is the name of the property being accessed
- __set( $property, $value ) When assigning a value to an undefined property, this method will be triggered. The parameters passed are the set property name and value
- The non-declaration here includes attributes whose access control is protected and private (that is, attributes that have no permission to access) when called using an object.
- 2, __isset, __unset
- __isset( $property ) This method is called when the isset() function is called on an undefined property
- __unset( $property ) This method is called when the unset() function is called on an undefined property
- The same as the __get method and __set method. The no declaration here includes when using an object call, the access control is protected, private attributes (that is, attributes without permission to access)
- 3.__call
- __call( $method, $arg_array ) This method is called when calling an undefined method
- The undefined methods here include methods that do not have permission to access; if the method does not exist, go to the parent class to find the method. If it does not exist in the parent class, call the __call() method of this class. If the __call() method does not exist in this class, go to the __call() method in the parent class
-
- 4.__autoload
- __autoload function, which is automatically called when trying to use a class that has not been defined yet. By calling this function, the scripting engine has a last chance to load the required classes before PHP fails with an error.
- If you want to define a global autoloading class, you must use the spl_autoload_register() method to register the processing class to the PHP standard library:
- view plaincopy to clipboardprint?
-
- class Loader
- {
- static function autoload_class($class_name)
- {
- }
- }
-
- spl_autoload_register(array('Loader', 'autoload_class'));
$a = - new Test();
//Test is instantiated without require to achieve automatic loading. Many frameworks use this method to automatically load classes -
?>
- Note: Exceptions thrown in the __autoload function cannot be caught by the catch statement block and cause fatal errors, so they should be caught in the function itself.
- 5. __construct, __destruct
- __construct constructor, this method is called when an object is created. The advantage of using this method compared to PHP4 is that the constructor can have a unique name, no matter what the name of the class it is in. In this way, you are changing When changing the name of the class, there is no need to change the name of the constructor
- __destruct Destructor method, PHP will call this method before the object is destroyed (that is, before it is cleared from memory). By default, PHP only releases the memory occupied by object properties and destroys object-related resources. The destructor allows you to execute arbitrary code to clear memory after using an object. When PHP decides that your script is no longer associated with the object, the destructor will be called.
- In the namespace of a function, this happens when the function returns.
- For global variables, this happens at the end of the script.
- If you want to explicitly destroy an object, you can assign any other value to the variable pointing to the object. Usually assign the variable to NULL or call unset.
- 6.__clone
- Object assignment in PHP5 uses reference assignment. If you want to copy an object, you need to use the clone method. When calling this method, the object will automatically call the __clone magic method. If you need to perform some initialization operations when copying the object, This can be achieved in the __clone method.
- 7.__toString
The - __toString method is automatically called when converting an object into a string, such as when using echo to print the object.
- If the class does not implement this method, the object cannot be printed through echo, otherwise it will display: Catchable fatal error: Object of class test could not be converted to string in
- This method must return a string.
- Before PHP 5.2.0, the __toString method can only take effect when used in conjunction with echo() or print(). After PHP 5.2.0, it can be used in any string environment (for example, through printf(), using the %s modifier), but it cannot be used in non-string environments (such as using the %d modifier). From PHP 5.2.0, if an object that does not define the __toString method is converted to a string, an E_RECOVERABLE_ERROR error will be reported.
- 8, __sleep, __wakeup
- __sleep is used when serializing
- __wakeup is called during deserialization
- serialize() checks whether there is a function with the magic name __sleep in the class. If so, the function will run before any serialization. It clears the object and should return an array containing the names of all variables in the object that should be serialized.
- The purpose of using __sleep is to close any database connections the object may have, submit pending data, or perform similar cleanup tasks. Additionally, this function is useful if you have very large objects that do not need to be stored completely.
- Conversely, unserialize() checks for the existence of a function with the magic name __wakeup . This function can reconstruct any resources the object may have, if present.
- The purpose of using __wakeup is to re-establish any database connections that may have been lost during serialization and to handle other re-initialization tasks.
- 9. __set_state
- This static method will be called when var_export() is called (valid since PHP 5.1.0).
- The only parameter of this method is an array, which contains class properties arranged in the format of array(’property’ => value, …).
- 10.__invoke
- When trying to call an object by calling a function, the __invoke method will be automatically called.
- PHP5.3.0 or above is valid
- 11. __callStatic
- It works similar to the __call() magic method, __callStatic() is to handle static method calls,
- PHP5.3.0 or above is valid
- PHP does strengthen the definition of the __callStatic() method; it must be public and must be declared static. Likewise, the __call() magic method must be defined as public, as must all other magic methods
Some configure parameters when compiling php
Php code
- ./configure
- –prefix=/usr/local/php php installation directory
- –with-apxs2=/usr/local/apache/bin/apxs
- –with-config-file-path=/usr/local/php/etc Specify the location of php.ini
- –with-mysql=/usr/local/mysql mysql installation directory, support for mysql
- –with-mysqli=/usr/local/mysql/bin/mysql_config mysqli file directory, optimized support
- –enable-safe-mode turn on safe mode
- –enable-ftp Turn on ftp support
- –enable-zip Turn on support for zip
- –with-bz2 Turn on support for bz2 files
- –with-jpeg-dir
–with-png-dir
- –with-freetype-dir Turn on support for freetype font library
- –without-iconv Turn off the iconv function and convert between character sets
- –with-libxml-dir Turn on support for libxml2 library
- –with-xmlrpc Open the c language of xml-rpc
- –with-zlib-dir
–with-gd Turn on support for gd library -
–enable-gd-native-ttf Support TrueType string function library -
–with-curl Turn on curl browsing tool support -
–with-curlwrappers Use curl tool to open url stream -
–with-ttf Open freetype1.* support, you don’t need to add it -
–with-xsl Open XSLT file support, extended libxml2 library, requires libxslt software -
–with-- gettext Open gnu’s
gettext support, the coding library uses -
–with-pear Turn on support for pear command, used for PHP extension
- –enable-calendar Turn on the calendar extension
- –enable-mbstring Multi-byte, string support
- –enable-bcmath Open image size adjustment, this module is used when using zabbix monitoring
- –enable-sockets Turn on sockets support
- –enable-exif Image metadata support
- –enable-magic-quotes Support for magic quotes
- –disable-rpath Turn off additional runtime files
- –disable-debug Turn off debug mode
- –with-mime-magic=/usr/share/file/magic.mime Magic header file location
- Parameters only used for cgi installation
- –enable-fpm This parameter is only available after applying the php-fpm patch. The startup program installed in cgi mode
- –enable-fastcgi Support fastcgi mode to start php
- –enable-force-cgi-redirect Same as above, there is no explanation in the help
- –with-ncurses A dynamic library that supports ncurses screen drawing and text terminal-based graphical interaction functions
- –enable-pcntl is needed for freeTDS, it may be used to link mssql
- Extensions of mhash and mcrypt algorithms
- –with-mcrypt Algorithm
- –with-mhash Algorithm
- –with-gmp
- –enable-inline-optimization
- –with-openssl Support for openssl, used for encrypted transmission
- –enable-dbase
- –with-pcre-dir=/usr/local/bin/pcre-config Perl regular library installation location
- –disable-dmalloc
- –with-gdbm gdbm support for dba
- –enable-sigchild
- –enable-sysvsem
- –enable-sysvshm
- –enable-zend-multibyte Support zend multibyte
- –enable-mbregex
- –enable-wddx
- –enable-shmop
- –enable-soap
- Full list of PHP configuration options
- Database options
- –with-dbplus
- Includes dbplus support.
- –with-adabas[=DIR]
- Includes Adabas D support. DIR is the basic installation directory of Adabas, which defaults to /usr/local.
- –with-sapdb[=DIR]
- Includes SAP DB support. DIR is the basic installation directory of SAP DB, which defaults to /usr/local.
- –with-solid[=DIR]
- Includes Solid support. DIR is the basic installation directory of Solid, which defaults to /usr/local/solid.
- –with-ibm-db2[=DIR]
- Includes IBM DB2 support.DIR is the basic installation directory of DB2, which defaults to /home/db2inst1/sqllib.
- –with-empress[=DIR]
- Includes Empress support. DIR is the basic installation directory of Empress, and the default is $EMPRESSPATH. Since PHP4, this option only supports Empress 8.60 and above.
- –with-empress-bcs[=DIR]
- Includes Empress Local Access support. DIR is the basic installation directory of Empress, and the default is $EMPRESSPATH. Since PHP4, this option only supports Empress 8.60 and above.
- –with-birdstep[=DIR]
- Includes Birdstep support. DIR is the basic installation directory of Birdstep, which defaults to /usr/local/birdstep.
- –with-custom-odbc[=DIR]
- Includes user-defined ODBC support. DIR is the basic installation directory of ODBC, which defaults to /usr/local. Make sure CUSTOM_ODBC_LIBS is defined and there is an odbc.h in the include directory. For example, for Sybase SQL Anywhere 5.5.00 under QNX, the following environment variables should be defined before running the configure script: CPPFLAGS=”-DODBC_QNX -DSQLANY_BUG” LDFLAGS=-lunix CUSTOM_ODBC_LIBS=”-ldblib -lodbc”.
- –with-iodbc[=DIR]
- Includes iODBC support. DIR is the basic installation directory of iODBC, which defaults to /usr/local.
- –with-esoob[=DIR]
- Includes Easysoft OOB support. DIR is the basic installation directory of OOB, the default is /usr/local/easysoft/oob/client.
- –with-unixODBC[=DIR]
- Includes unixODBC support. DIR is the basic installation directory of unixODBC, which defaults to /usr/local.
- –with-openlink[=DIR]
- Includes OpenLink ODBC support. DIR is the basic installation directory of OpenLink, which defaults to /usr/local. This is the same as iODBC.
- –with-dbmaker[=DIR]
- Includes DBMaker support. DIR is the basic installation directory of DBMaker, which defaults to the directory where the latest version of DBMaker is installed (for example, /home/dbmaker/3.6).
- –disable-unified-odbc
- Remove support for unified ODBC. Only applicable if iODBC, Adabas, Solid, Velocis or user-defined ODBC interface is activated. Only works with PHP 3!
- Image options
- –without-gd
- Disable GD support. Only for PHP 3!
- –with-imagick
- The Imagick extension has been moved to PECL in PEAR and can be found here. Installation instructions for PHP 4 can be found on the PEAR site.
- Using --with-imagick is only supported in PHP 3 unless you follow the instructions on the PEAR site.
- –with-ming[=DIR]
- Includes ming support.
- Miscellaneous options
- –enable-force-cgi-redirect
- Activate security checks for internal server redirections. This option should be used if PHP is used in CGI mode with Apache.
- –enable-discard-path
- Using this option allows PHP's CGI executable program to be safely placed outside the web directory tree, and others cannot bypass the security settings of .htaccess.
- –with-fastcgi
- Compile PHP into FastCGI application.
- –enable-debug
- Add debugging symbols when compiling.
- –with-layout=TYPE
- Set the file layout after installation. TYPE can be PHP (default) or GNU.
- –with-pear=DIR
- Install PEAR in the DIR directory (default is PREFIX/lib/php).
- –without-pear
- Do not install PEAR.
- –enable-sigchild
- Activate PHP's own SIGCHLD handle.
- –disable-rpath
- Disable passing additional runtime library search paths.
- –enable-libgcc
- Activate explicit libgcc linkage.
- –enable-php-streams
- Contains experimental PHP streams. Don't use it unless you are testing the source code!
- –with-zlib-dir=;
- Define the installation path of zlib.
- –with-aspell[=DIR]
- Contains ASPELL support.
- –with-ccvs[=DIR]
- Contains CCVS support.
- –with-cybercash[=DIR]
- Includes CyberCash support. DIR is the installation directory of CyberCash MCK.
- –with-icap[=DIR]
- Contains ICAP support.
- –with-ircg-config
- The path to the ircg-config script.
- –with-ircg
- Contains ircg support.
- –enable-mailparse
- Contains mailparse support.
- –with-muscat[=DIR]
- Contains muscat support.
- –with-satellite[=DIR]
- Activate CORBA support via Satellite (experimental). DIR is the home directory of ORBit.
- –enable-trans-sid
- Activate transparent session id propagation.
- –with-regex[=TYPE]
- Use system regex library (deprecated).
- –with-vpopmail[=DIR]
- Includes vpopmail support.
- –with-tsrm-pthreads
- Use POSIX threads (default).
- –enable-shared[=PKGS]
- Compile shared libraries [default=yes].
- –enable-static[=PKGS]
- Compile static library [default=yes].
- –enable-fast-install[=PKGS]
- Optimized for fast installation [default=yes].
- –with-gnu-ld
- Assume that the C compiler uses GNU ld [default=no].
- –disable-libtool-lock
- Avoid locking (which may break parallel compilation).
- –with-pic
- Try to use only PIC/non-PIC objects [default=use both].
- –enable-memory-limit
- Add memory limit support when compiling.
- –disable-url-fopen-wrapper
- The fopen wrapper via URL is prohibited, and files cannot be accessed via HTTP or FTP.
- –enable-versioning
- Only output the required symbols. See the INSTALL file for more information.
- –with-imsp[=DIR]
- Includes IMSP support (DIR is IMSP's include directory and libimsp.a directory). Only for PHP 3!
- –with-mck[=DIR]
- Includes Cybercash MCK support. DIR is the cybercash mck compilation directory, the default is /usr/src/mck-3.2.0.3-linux. See extra/cyberlib for help. Only for PHP 3!
- –with-mod-dav=DIR
- Contains DAV support via Apache's mod_dav. DIR is the installation directory of mod_dav (only for Apache module versions!) Only for PHP 3!
- –enable-debugger
- Compile into remote debugging functions. Only for PHP 3!
- –enable-versioning
- Take advantage of version control and scope provided by Solaris 2.x and Linux. Only for PHP 3!
- PHP Options
- –enable-maintainer-mode
- Activation puts compilation rules and unused (and some obfuscated) dependency files into a temporary installation.
- –with-config-file-path=PATH
- Set the path where php.ini is located. The default is PREFIX/lib.
- –enable-safe-mode
- Safe mode is activated by default.
- –with-exec-dir[=DIR]
- In safe mode, only programs in this directory are allowed to execute. The default is /usr/local/php/bin.
- –enable-magic-quotes
- Magic quotes are activated by default.
- –disable-short-tags
- The abbreviated PHP start tag is prohibited by default.
- Server Options
- –with-aolserver=DIR
- Specify the path to the installed AOLserver.
- –with-apxs[=FILE]
- Compile shared Apache module. FILE is the path to the optional Apache apxs tool, which defaults to apxs. Make sure that the specified apxs version is the installed file and not the package in the Apache source program.
- –with-apache[=DIR]
- Compile Apache module. DIR is the highest-level directory of Apache source programs. The default is /usr/local/apache.
- –with-mod_charset
- Activate the transfer table in mod_charset (in Apache).
- –with-apxs2[=FILE]
- Compile shared Apache 2.0 modules. FILE is the path to the optional Apache apxs tool, which defaults to apxs.
- –with-fhttpd[=DIR]
- Compile the fhttpd module. DIR is the source code path of fhttpd, which defaults to /usr/local/src/fhttpd.
- –with-isapi=DIR
- Compile PHP to ISAPI module for Zeus.
- –with-nsapi=DIR
- Specify the path to the installed Netscape server.
- –with-phttpd=DIR
- No information yet.
- –with-pi3web=DIR
- Compile PHP into a module for Pi3Web.
- –with-roxen=DIR
- Compile PHP into a Pike module. DIR is the root directory of Roxen, usually /usr/local/roxen/server.
- –enable-roxen-zts
- Compile Roxen module and use Zend Thread Safety.
- –with-servlet[=DIR]
- Contains servlet support. DIR is the basic installation directory of JSDK. This SAPI requires a java extension that must be compiled into a shared dl.
- –with-thttpd=SRCDIR
- Compile PHP into thttpd module.
- –with-tux=MODULEDIR
Two ways to pass parameters to php.
(mysql) Please write the meaning of data type (int char varchar datetime text); What is the difference between varchar and char;
Sql code
- char is a fixed-length type, and varchar is a variable-length type. The difference between them is:
-
- In a data column of type char(M), each value occupies M bytes. If a length is less than M, MySQL will pad it with space characters on the right. (The padded space characters will be removed during the retrieval operation) In the varchar(M) type data column, each value only occupies just enough bytes plus one to record its length. Bytes (that is, the total length is L+1 bytes).
-
- Rules used in MySQL to determine whether column type conversion is required
-
- 1. In a data table, if the length of each data column is fixed, then the length of each data row will also be fixed.
- 2. As long as there is a variable length of data column in the data table, then the length of each data row is variable.
- 3. If the length of the data rows in a data table is variable, then, in order to save storage space, MySQL will convert the fixed-length data columns in the data table into the corresponding variable-length type. .
- Exception: char data columns less than 4 characters in length will not be converted to varchar type
-
- A fixed length
- An indefinite length
- a char(10)
- b varchar(10)
- Deposit all into 'abc'
- a 10 bytes
- b 3 bytes
Error_reporting and other debugging functions are used
Have you ever used version control software? If so, what is the name of the version control software you used?
The difference between posix and perl standard regular expressions;
Php code
- Regular Expression (abbreviated as regexp, regex or regxp), also known as regular expression, regular expression or regular expression or normalized expression or regular expression, refers to a method used to describe or match A sequence of individual strings that conform to a certain syntax rule. In many text editors or other tools, regular expressions are often used to retrieve and/or replace text content that matches a certain pattern. Many programming languages support string manipulation using regular expressions. For example, Perl has a powerful regular expression engine built into it. The concept of regular expressions was originally popularized by tool software in Unix (such as sed and grep). (Excerpted from Wikipedia)
-
- PHP uses two sets of regular expression rules at the same time. One is the POSIX Extended 1003.2 compatible regular expression formulated by the Institute of Electrical and Electronics Engineers (IEEE) (in fact, PHP's support for this standard is not perfect), and the other is from The PCRE (Perl Compatible Regular Expression) library provides PERL-compatible regular expressions. This is an open source software authored by Philip Hazel.
-
- The functions that use POSIX compatibility rules are:
- ereg_replace()
- ereg()
- eregi()
- eregi_replace()
- split()
- spliti()
- sql_regcase()
- mb_ereg_match()
- mb_ereg_replace()
- mb_ereg_search_getpos()
- mb_ereg_search_getregs()
- mb_ereg_search_init()
- mb_ereg_search_pos()
- mb_ereg_search_regs()
- mb_ereg_search_setpos()
- mb_ereg_search()
- mb_ereg()
- mb_eregi_replace()
- mb_eregi()
- mb_regex_encoding()
- mb_regex_set_options()
- mb_split()
-
- Functions that use PERL compatibility rules are:
- preg_grep()
- preg_replace_callback()
- preg_match_all()
- preg_match()
- preg_quote()
- preg_split()
- preg_replace()
-
- Delimiter:
-
- POSIX-compatible regular expressions have no delimiters, and the corresponding parameters of the function will be considered regular expressions.
-
- PERL-compatible regular expressions can use any character that is not a letter, number, or backslash () as a delimiter. If the character as a delimiter must be used in the expression itself, it needs to be escaped with a backslash. . You can also use (), {}, [] and as delimiters
-
- Modifier:
-
- POSIX compatible regular expressions have no modifiers.
-
- Possible modifiers used in PERL compatible regular expressions (spaces and newlines in the modifiers are ignored, other characters will cause errors):
-
- i (PCRE_CASELESS):
- Ignore case when matching.
-
- m (PCRE_MULTILINE):
- When this modifier is set, the start of line (^) and the end of line ($) not only match the beginning and end of the entire string, but also match after and before the newline character (n).
-
- s (PCRE_DOTALL):
- If this modifier is set, the dot metacharacter (.) in the pattern matches all characters, including newlines. Without this setting, newline characters are not included.
-
- x(PCRE_EXTENDED):
- If this modifier is set, whitespace characters in the pattern are completely ignored except those that are escaped or within a character class.
-
- e:
- If this modifier is set, preg_replace() performs the normal replacement of the backreference in the replacement string, evaluates it as PHP code, and uses its result to replace the searched string. Only preg_replace() uses this modifier, other PCRE functions ignore it.
-
- A (PCRE_ANCHORED):
- If this modifier is set, the pattern is forced to be "anchored", that is, it is forced to match only from the beginning of the target string.
-
- D (PCRE_DOLLAR_ENDONLY):
- If this modifier is set, end-of-line ($) in the pattern only matches the end of the target string. Without this option, if the last character is a newline character, it will also be matched. This option is ignored if the m modifier is set.
-
- S:
- When a pattern is going to be used several times, it is worth analyzing it first to speed up matching. If this modifier is set additional analysis will be performed. Currently, analyzing a pattern is only useful for non-anchored patterns that do not have a single fixed starting character.
-
- U(PCRE_UNGREEDY):
- Make the default matching of "?" greedy.
-
- X (PCRE_EXTRA):
Any backslash in the - pattern followed by a letter with no special meaning results in an error, thus preserving this combination for future expansion. By default, a backslash followed by a letter with no special meaning is treated as the letter itself.
-
- u(PCRE_UTF8):
- Pattern strings are treated as UTF-8.
-
- Logical segmentation:
-
- The logical separator symbols of POSIX compatible regular expressions and PERL compatible regular expressions have exactly the same function and usage:
- []: Contains information related to any selected operation.
- {}: Contains information about the number of matches.
- (): Contains relevant information of a logical interval and can be used for reference operations.
- |: means "or", [ab] and a|b are equivalent.
-
The - metacharacter is related to "[]":
-
- There are two different sets of metacharacters: one is recognized within the pattern except square brackets, and the other is recognized within square brackets "[]".
-
- POSIX compatible regular and PERL compatible regular "[]" and "consistent" metacharacters:
- Universal escape character with several uses
- ^ matches the beginning of the string
- $ matches the end of the string
- ? Matches 0 or 1
- * matches 0 or more characters of the previously specified type
- + matches 1 or more characters of the previously specified type
-
- POSIX compatible regular and PERL compatible regular "[]" and "inconsistent" metacharacters:
- . PERL compatible regular match any character except newline character
- . POSIX compatible regular match any character
-
- POSIX compatible regular and PERL compatible regular "within []" "consistent" metacharacters:
- Universal escape character with several uses
- ^ negates the character, but is only valid when it is the first character
- - Specify the character ASCII range, study the ASCII code carefully, you will find that [W-c] is equivalent to [WXYZ\^_`abc]
-
- POSIX compatible regular and PERL compatible regular "inconsistent" metacharacters "within []":
- - The specification of [a-c-e] in POSIX compatible regular expressions will throw an error.
- - The specification of [a-c-e] in PERL compatible regular expressions is equivalent to [a-e].
-
- The number of matches is related to "{}":
-
- POSIX compatible regular expressions and PERL compatible regular expressions are exactly the same in terms of matching times:
- {2}: Indicates matching the previous character 2 times
- {2,}: Indicates matching the previous character 2 or more times. The default is greedy (as many as possible) matching
- {2,4}: Indicates matching the previous character 2 or 4 times
-
- Logical intervals are related to "()":
-
- The area enclosed by () is a logical interval. The main function of the logical interval is to reflect the logical order in which some characters appear. Another use is that it can be used for reference (the value in this interval can be referenced to a variable ).The latter effect is rather strange:
-
- $str = "http://www.163.com/";
- echo ereg_replace("(.+)","\1",$str);
- echo preg_replace("/(.+)/","$1",$str);
- ?>
-
- When quoting, brackets can be nested, and the logical order is calibrated according to the order in which "(" appears.
-
- Type matching:
-
- POSIX compatible regex:
- [:upper:]: Match all uppercase letters
- [:lower:]: Match all lowercase letters
- [:alpha:]: Match all letters
- [:alnum:]: Match all letters and numbers
- [:digit:]: Match all digits
- [:xdigit:]: matches all hexadecimal characters, equivalent to [0-9A-Fa-f]
- [:punct:]: matches all punctuation marks, equivalent to [.,"'?!;:]
- [:blank:]: matches spaces and TAB, equivalent to [t]
- [:space:]: matches all whitespace characters, equivalent to [tnrfv]
- [:cntrl:]: Matches all control characters between ASCII 0 and 31.
- [:graph:]: matches all printable characters, equivalent to: [^ tnrfv]
- [:print:]: matches all printable characters and spaces, equivalent to: [^tnrfv]
- [.c.]: Unknown function
- [=c=]:Unknown function
- [:<: matches the beginning of a word>
- [:>:]: Match the end of the word
-
- PERL compatible regular expressions (here you can see the power of PERL regular expressions):
- a alarm, which is the BEL character (’0)
- cx "control-x", where x is any character
- e escape(’0B)
- f formfeed (’0C)
- n newline character newline (’0A)
- r Carriage return(’0D)
- t tab (’0)
- xhh The character whose hexadecimal code is hh
- ddd The character whose octal code is ddd , or backreference
- d Any decimal number
- D Any non-decimal character
- s any whitespace character
- S Any non-whitespace character
- w Any character of "word"
- W Any "non-word" character
- b word dividing line
- B non-character dividing line
- Beginning of A target (independent of multiline mode)
- Z End of target or before trailing newline (independent of multiline mode)
- z end of target (independent of multiline mode)
- G first matching position in target
What areas are restricted after Safe_mode is turned on?
Write code to solve the problem of multiple processes/threads reading and writing a file at the same time.
Php code
- As we all know, PHP does not have the concept of multi-threading. However, we can still use "imperfect" methods to simulate multi-threading. Simply put, it is queue processing. This is achieved by locking and unlocking files. When a file is operated by one user, the file is locked, and other users can only wait. It is indeed not perfect, but it can also meet some applications with low requirements.
- function T_put($filename,$string){
- $fp = fopen($filename,'a');
- if (flock($fp, LOCK_EX)){
- fputs($fp,$string);
- flock($fp, LOCK_UN);
- }
- fclose($fp);
- }
- function T_get($filename,$length){
- $fp = fopen($filename,'r');
- if (flock($fp, LOCK_SH)){
-
$result = fgets($fp,$length);
- flock($fp, LOCK_UN);
- }
- fclose($fp);
- return $result;
- }
Write a piece of code to upload files.
Mysql storage engine, the difference between myisam and innodb.
Sql code
- Simple expression.
- MyISAM is a non-transactional storage engine.
- Innodb is a storage engine that supports transactions.
-
- The innodb engine is more suitable for applications with a lot of insert and update operations
- MyISAM is suitable for applications with frequent queries
-
- MyISAM
- innodb
- MyISAM will not cause deadlock.
-
- The biggest difference is that MYISAM is suitable for small data and small concurrency; INNODB is suitable for big data and large concurrency. The biggest difference is at the lock level.
-
- The MyISAM type does not support advanced processing such as transaction processing, while the InnoDB type does. The MyISAM type table emphasizes performance, and its execution times are faster than the InnoDB type, but it does not provide transaction support, while InnoDB provides transaction support and advanced database functions such as foreign keys. To summarize, different storage types can be used according to the different uses of the data table. Moreover, MyISAM is file storage and can be copied directly between different operating systems.
-
- InnoDB:
- InnoDB provides MySQL with transaction-safe (transaction-safe (ACID compliant)) type with transaction (commit), rollback (rollback) and crash recovery capabilities (crash recovery capabilities) surface. InnoDB provides row locking (locking on row level) and non-locking read (non-locking read in SELECTs) consistent with Oracle type. These features improve the performance of multi-user concurrent operations. There is no need to expand locks (lock escalation) in InnoDB tables because InnoDB's column locks (row level locks) fit in very small spaces. InnoDB is the first table engine on MySQL to provide foreign key constraints (FOREIGN KEY constraints). InnoDB is designed to handle large-capacity database systems, and its CPU utilization is unmatched by other disk-based relational database engines. Technically, InnoDB is a complete database system placed in the background of MySQL. InnoDB establishes its own dedicated buffer pool in main memory for caching data and indexes. InnoDB stores data and indexes in a table space, which may contain multiple files, which is different from others. For example, in MyISAM, tables are stored in separate files. The size of an InnoDB table is limited only by the file size of the operating system, which is typically 2 GB. All tables in InnoDB are stored in the same data file ibdata1 (it may be multiple files, or independent table space files). It is relatively difficult to back up. You can copy the file or use navicat for mysql.
-
- MyISAM
- Each MyISAM table is stored in three files: the frm file stores the table definition. The data file is MYD (MYData). The index file is an extension of MYI (MYIndex).
- Because MyISAM is relatively simple, it is better than InnoDB in terms of efficiency. It is a good choice for small applications to use MyISAM.
- MyISAM tables are saved as files. Using MyISAM storage in cross-platform data transfer will save a lot of trouble
2. Web architecture, security, project experience
3. Basic use of unix/linux
4. Front-end, HTML, JS
Which of the following sentences will not add John to the users array?
$users[] = 'john';
Successfully added John to the users array.
array_add($users,’john’);
Function array_add() has no definition.
array_push($users,‘john’);
Successfully added John to the array users.
$users ||= 'john';
Syntax error.
2. What are the differences between sort(), assort(), and ksort()? Under what circumstances are they used?
sort()
Sort in English alphabetical order according to the value of the elements in the array, and the index keys will be renumbered from 0 to n-1. Mainly used to sort the array when the value of the array index key is irrelevant.
assort()
PHP does not have assort() function, so it may be a typo in asort().
asort()
Like sort(), it arranges the elements of the array in English alphabetical order. The difference is that all index keys are retained, which is especially suitable for sorting associative arrays.
ksort()
Sort in English alphabetical order according to the value of the index key in the array. It is especially suitable for associative arrays that want to sort the index keys.
3. What will the following code produce? Why?
$num =10;
function multiply(){
$num =$num *10;
}
multiply();
echo $num;
Due to function The formula multiply() does not specify $num as a global variable (such as global $num or $_GLOBALS['num']), so the value of $num is 10.
4. What is the difference between a reference and a regular variable? How to pass by reference? Under what circumstances do we need to do this?
Reference transfers the address of the variable rather than its value, so when the value of a variable is changed in a function, the entire application will see the variable.