String functions are indispensable during development. there are too many functions and it is a little impossible to back them up. However, if you use a function, you should know which function can be implemented.
String functions are indispensable during development. there are too many functions and it is a little impossible to back them up. However, when using a function, you should also know which function can be implemented, at least I need to be impressed. let's start to learn about the php string functions. Remember to be impressed!
/**
String function learning
*/
// Trim (string [, deleted letter]) deletes the white space between the left and right sides of the string
// Ltrim () // delete the white space on the left of the string
// Rtrim () // delete the white space on the right of the string
$ _ Str = "helloh world ";
Echo "++ ";
Echo trim ($ _ str, 'hdelo ');
Echo "------";
Exit;
// Str_replace (Replaced content, replaced content, string) string replacement
// 3. str_replace (arr, arr, str );
$ _ Str = "today, is, Thursday, and, I, am, happy ";
$ Arr1 = array ('today', 'is ');
$ Arr2 = array ('tommorow', 'was ');
Echo str_replace ($ arr1, $ arr2, $ _ str );
Exit;
// 2. str_replace (arr, str, str );
$ _ Str = "today, is, Thursday, and, I, am, happy ";
$ Arr = array ('today', 'is ');
Echo str_replace ($ arr, 'tommorow', $ _ str );
Exit;
// 1. str_replace (str, str, str)
$ _ Str = "today, is, Thursday, and, I, am, happy ";
Echo str_replace ('today', 'tommorow', $ _ str );
Exit;
// Substr (target string, start position, length) intercepts the string [the most important function of the string]
// Start from 0 on the left
// Start from-1 on the right
$ _ Str = "today, is, Thursday, and, I, am, happy ";
// Echo substr ($ _ str, 9, 8); // Thursday
// Echo substr ($ _ str,-9, 8); //, am, happ
// Echo substr ($ _ str,-9,-8 );//,
// Echo substr ($ _ str, 9,-8); // Thursday, and, I,
Echo substr ($ _ str, 9,-24 );
Exit;
// Implode ([separator,] array) combines array elements into a string
$ _ Arr = array ('A', 'B', 'C ');
Echo implode ('-', $ _ arr );
Exit;
// Explode (separator, string) // splits the string into small units of information and returns an array.
$ _ Str = "today, is, Thursday, and, I, am, happy ";
Print_r (explode (',', $ _ str ));
Exit;
/**
String definition
String definition: single quotation marks, double quotation marks, and delimiters
Single quotes :\'\\
Double quotation marks: \ $ \ n \ r \ t "\\\[\{
Delimiters: < Delimiter content
Eof;
*/
$ Abc = <