Home > Backend Development > PHP Tutorial > PHP learning scattered notes - string splitting, fetch function and single and double quotation marks.

PHP learning scattered notes - string splitting, fetch function and single and double quotation marks.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:11:35
Original
867 people have browsed it

1 String splitting - split() function and preg_split() function

split - use regular expression to split the string into an array - it seems that PHP5.3 and above has deprecated its use
array split ( string $pattern , string $string [, int $limit ] )

preg_split — Split a string by a regular expression

array preg_split ( string $pattern , string $subject [, int $limit = -1 [, int $flags = 0 ]] )

The same thing: they all use regular expressions to split strings.
split() is simpler to use. For example, to split "2008-12-16 15:48:12", split can be written like split(['- :'])
while preg_split() is more complicated. You have to write preg_split("/[s-:]/")
The reason is: split() only supports POSIX-style regular expressions, while preg_split only supports Perl-style regular expressions
POSIX style is simpler than Perl style, but it is not binary safe

By the way, there is also explode(), which is different from the above two functions in that it uses strings to split strings.

array explode ( string $delimiter , string $string [, int $limit ] )

Use one string to split another string

Note: There are many binary security explanations on the Internet, I feel The following explanation is helpful for understanding the above sentence:

The binary-safe function only cares about the binary string and does not care about the specific format of the string. It will only access the binary data strictly, not The data is parsed in a special format.

2 The difference between mysqli::fetch_array and mysqli::fetch_row

mysqli_result::fetch_row()

Get a row from the result set as an enumeration array

mixed my sqli_result::fetch_array ([ int $resulttype = MYSQLI_BOTH ] )

Get a row from the result set as an associative array, or a numeric array, or both

The manual says there doesn’t seem to be much difference in performance between the two, The former is the latter Enhanced version of

3 Single quotes and double quotes
The two string types of php, single quotes and double quotes.
The single-quoted string is plain text (real text), which will be sent directly to the browser without modification, whether it is a variable name or any other text.
Double-quoted string, PHP will try to calculate the double-quoted string, and the variable name will be replaced by the variable value.
Here, the concepts of variables, strings, text and raw data cannot be confused:
Variables are symbols that represent data, variables are represented by variable names, symbols that represent data
while strings with single quotes are It is text, and it (literal value) is the original data
The key is to understand the difference between text and variables. Text is data, and variables are symbols of data.

You can take a look at the introduction to strings on page 12 of the Chinese version of "PHP and MySQL Web Development (Original Book 4th Edition)".

Reference:

"PHP and MySQL Web Development (Original Book 4th Edition)" Chinese version, page 12, by Luke Welling & Laura Thomson

The meaning of php binary string http ://www.lofter.com/postentry?from=search&permalink=139418_34c583

Zhihu: What does binary security mean? http://www.zhihu.com/question/28705562

The above introduces the scattered notes of PHP learning - string splitting, fetch function and single and double quotation marks. , including regular expressions, I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template