Blog posted on 2016 0531.11:30
Handling of strings
A summary of some of the methods that may be used is mainly:
First common words
1.strlen () string length
$a = "HI"; echo strlen ($a);
The result is 2.
2.STRCMP () string comparison, case-sensitive, same return 0
Var_dump (strcmp ("Hello", "Hello")); The result is int1.
Var_dump (strcmp ("A", "B")); The result is int-1.
3,STRCASECMP () string comparison, case insensitive, same return 0,
Echo strcasecmp ("A", "a"); The returned result is int 0
4. Strtolower () Turn lowercase
$a =app
echo strtolower ($a); The result is an app
5,strtoupper () Turn capital,
echo strtoupper ($a);
Ditto for the opposite meaning
6.explode () split string, split into array (returns an array)
$a = "N01XN02XN03XN04;"
$attr =explode ("x", $a); X is a separator
Var_dump ($ATTR);
The result is:
Array (size=4)
0=>string ' No1 ' (lenght=3)
1=>string ' NO2 ' (lenght=3)
2=>string ' NO3 ' (lenght=3)
3=>string ' No4 ' (lenght=3)
* The use of the more common
Example database 1 content Lookup
2 answers to the question selection questions
7,implode () stitching array elements into a string
$a = "N01/n02/n03/n04"
Implode (">", $attr)
The result is n01>n02>n03>n04.
8. Substr_replace (string,replacement,start,length) * Replace string, replace specified position
Substr_replace ($a, "xx", 0,4) replaces the contents of the specified position with "XX"
9 Str_replace (find,replace,string) replaces some characters in a string with other characters
Find replacements
Echo Str_replace ("n", "M", $a);
Replace All "n" in $ A with "M"
Ten substr () intercept characters
Subsre ($a, 0,4) intercepts characters from $ A 0 in length lenght=4
$STR = array
(
Array ("n001", "Han"),
Array ("n002", "Hui"),
Array ("n003", "Miao")
);
$a = "n001^ han |n002^ hui |n003^ miao Nationality |";
Echo substr ($a, 0,strlen ($a)-1);
Regular expressions
Arrays and data structures in PHP
String processing of PHP learning notes