Home > Article > Backend Development > php substr(),explode(),strrev()_PHP tutorial
substr(str,start,length);
Example: substr('php tutorial is very good language',4,5);
The output is is ve;
When start>str length, the return is ();
substr('php is very good language',26,5);
substr('php is very good language',4);
The output is (blank)
The output is is v (indicating that both start and langth are 4)
When start is a negative value, reading starts from the end of str (*In this case, reading starts from -1 instead of starting from 0),
substr('php is very good language',-4,5);
The output is uage
When length is a negative value, length means reading from the end and intercepting the end position of str.
substr('php is very good language',4,-5);
The output is is very good lan
explode() splits the function string into an array;
// example 1
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
// example 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $gecos."
"; // foo
echo $shell; // *
strrev() outputs the string from back to front
echo strrev("june"); // outputs "enuj"
setlocalhost(content location) sets the local environment.content and specifies the scene information constants that need to be set (
lc_all – constant for all subordinates
lc_collate – collation order
lc_ctype – character classification and conversion (for example: convert all characters to lowercase or uppercase)
lc_messages – System message format
lc_monetary – currency/currency format
lc_numeric – Numeric format
lc_time – date and time format
); location, set the country area, for example, chs.