Home  >  Article  >  Backend Development  >  PHP learning scattered notes - string splitting, fetch function and single and double quotes. , fetch double quotes_PHP tutorial

PHP learning scattered notes - string splitting, fetch function and single and double quotes. , fetch double quotes_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:04:20797browse

Scattered notes on PHP learning—string splitting, fetch function, and single and double quotes. , fetch double quotes

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

split — Use regular expressions to split a string into an array - it seems that PHP 5.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 ]] )

Same point: both use regular expressions to split strings.
split() is easier to use. For example, to split "2008-12-16 15:48:12", split can be written like this: split(['- :'])
And preg_split() is more complicated, so you have to write preg_split("/[s-:]/")
The reason is: split() only supports POSIX-style regular expressions formula, 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. It uses strings to split strings.

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

Split one string into another

Note: There are many explanations of binary security on the Internet. I feel that the following explanation is helpful in 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 and will not parse the data 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 mysqli_result::fetch_array ([ int $resulttype = MYSQLI_BOTH ] )

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

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

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), and it 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, which represent data. The symbol
and the single-quoted string is text, itself (literal value) is the original data
The key is to understand the difference between text and variables, text is data , 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1073811.htmlTechArticlePHP learning scattered notes - string splitting, fetch function and single and double quotation marks. , fetch double quotes 1 String split split() function and preg_split() function split uses regular expressions to split the string...
Statement:
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