Summary of the differences between STRSTR, STRRCHR, substr, stristr four functions in PHP, STRSTRSTRISTR
PHP strstr, STRRCHR, substr, stristr four function usage differences:
PHP strstr STRRCHR substr stristr These four string manipulation functions are particularly confusing, commonly used is substr,strstr, basically can satisfy the operation of the string.
Here's a look at the differences between the several functions.
The difference between STRSTR and STRCCHR
STRSTR displays the string that was found for the first time, to find, and subsequent strings.
The STRRCHR displays the string that was last found, to find, and subsequent strings.
Copy the Code code as follows:
<?php
$email = ' test@test.com@jb51.net ';
$domain = Strstr ($email, ' @ ');
echo "STRSTR test results $domain
";
$domain = STRRCHR ($email, ' @ ');
echo "STRRCHR test results $domain
";
?>
The results are as follows:
STRSTR test results @test. com@jb51.net
STRRCHR test results @jb51. Net
Ii. the difference between strstr and STRISTR
STRSTR is case-sensitive.
STRISTR is case insensitive.
Copy the Code code as follows:
<?php
$email = ' zhangYing@jb51.net ';
$domain = Strstr ($email, ' Y ');
echo "STRSTR test results $domain
";
$domain = Stristr ($email, ' Y ');
echo "STRISTR test results $domain
";
?>
The results are as follows:
STRSTR Test Results Jb51.net
STRISTR Test Results Ying@jb51.net
Iii. the difference between strstr and substr
STRSR is matched after interception.
SUBSTR is not matched and is intercepted according to the starting position.
Copy the Code code as follows:
<?php
$email = ' zhangYing@jb51.net ';
$domain = Strstr ($email, ' Y ');
echo "STRSTR test results $domain
";
$domain = substr ($email,-7);
echo "substr test results $domain
";
?>
The results are as follows:
STRSTR Test Results Jb51.net
SUBSTR Test Results Jb51.net
The string intercept function to understand, in development can save a lot of things
How does the PHP function return an array, for example,
$a = array ();
$a [] = "project";
$a [] = "title";
$a [] = "Time";
Return $a
PHP Common functions
In fact, there is no need to go around the so-called "common functions", so-called commonly used is different, someone often use a function, but does not mean that you will always use. PHP function A lot, standing PHP help manual is the key, encountered unfamiliar on the check, check the number of times, naturally become "common".
In general, the functions of strings, arrays, and database classes are relative to the use of more than one category.
Here is a list of functions, for reference only.
============================================
=============================== Time Date ===============================
Y returns the last two digits of the year, the Y-year four digits, the M-month number, and the M-month English. D Month Date number, D week a few English
$date =date ("y-m-d");
Include,include_once.require,require_once
Require ("file.php") will be read into the file specified by require before the PHP program executes, if the error is fatal.
The Include ("file.php") can be placed anywhere in the PHP program, and the PHP program will read into the include specified file when it is executed, such as an error prompting
=============================== Output Print ===============================
sprintf ("%d", "3.2");//format only, return formatted string, not output.
printf ("%d", "3.2");//format and output
Print ("3.2");//Output only
echo "Nihao", "AA";//can output multiple strings
Print_r (Array ("A", "B", "C"));//The array's key values and elements are displayed sequentially
=============================== commonly used String functions ===============================
Gets the string length, the number of characters, the space is also counted
$STR = "Sdaf SD";
$len =strlen ($STR);
Use the string in the first argument to concatenate each element in the following array and return a string.
$str =implode ("-", Array ("A", "B", "C"));
String segmentation method, return an array, with the characters in the first argument to split the following string, the specified characters are truncated before and after the character, if the specified character at the beginning or end of the returned array of the beginning or end of the element is an empty string
A null value is returned to the corresponding element of the array without splitting it into a string. The last limit returns the length of the array, which is not limited, and is always split down.
$array =explode ("A", "ASDD ... Remaining full text >>
http://www.bkjia.com/PHPjc/882914.html www.bkjia.com true http://www.bkjia.com/PHPjc/882914.html techarticle php strstr, STRRCHR, substr, stristr four functions of the difference summary, strstrstristr in PHP strstr, STRRCHR, substr, stristr four function usage differences: PHP strstr strrchr subst ...