PHP functions are all capabilities, built more than 1,000 functions, not every function can be used directly by default, some need to install or enable additional "plug-in" expansion.
1, to get the string length
<?php $str='hello'; echo strlen($str); //5
2, Chinese character string obtaining length (width characters)
strlen can only get the length of Latin
php in a set of API to add special characters wide, all of the API are mb_xxxx
echo mb_strlen ( 'Hello');
但是报错:Fatal error: Uncaught Error: Call to undefined function mb_strlen() in D:\www\site2\02, string.php:7 Stack trace: #0 {main} thrown in D:\www\site2\02, string.php on line 7
This is because it is not built-in set of API 1000+ inside, but in a module (php_mbstring.dll), the module members must use the module again after loading a configuration file
Configuration steps PHP extension
1, to create a php.ini in the PHP installation directory (the php.ini-development PHP directory to copy a modified php.ini)
2, modify the extension file directory extension_dir
3,; extension = php mbstring.dll, uncomment (some options to modify the file; is the Notes)
4, the default Apache is loaded php.ini to C: \ Windows directory to find the
5, the load path can modify the default configuration file of Apache by PHPIniDir
3, common string API
① string interception
The first parameter: the intercepted string
The second argument: cut out where to begin
The number of characters taken: the third parameter
② string length
③ case conversion
strtolower: uppercase lowercase turn
strtoupper: uppercase lowercase turn
④ remove whitespace characters from beginning to end
⑤ find some of the characters in the string position for the first time
⑥ string replacement
Replacing a with b
⑦ Repeat string
The first parameter: repeat string
The second argument: repeated many times
⑧ string split
4, array processing
Array type in php: indexed arrays, associative array
php array defined manner: array (), [] (php 5.4+)
① associative array acquires all key / value
arrar_keys() array_values()
<? PHP $ ARR = Array ( ' Hello ' => ' Hello ' , ' Pink ' => ' pink ' , ' Blue ' => ' blue ' , ); var_dump (arrray_key ($ ARR)); // [ 'Hello', 'pink', 'blue'];
var_dump (array_values ($ ARR)); // [ 'Hello', 'pink', 'blue'];
② determine whether there is a key array
array_key_exists()
<?php $arr=array( 'hello' => '你好', 'pink' => '粉色', 'blue' => '蓝色', ); var_dump(array_key_exists('hello',$arr)); //bool(true) var_dump(array_key_exists('world',$arr)); //bool(false)
isset may also determine whether a specified key array
<? PHP $ ARR = Array ( ' Hello ' => ' Hello ' , ' Pink ' => ' pink ' , ' Blue ' => ' blue ' , ); IF (isset (ARR $ [ ' Hello ' ] )) { echo $ ARR [ ' Hello ' ]; // hello } the else { echo ' no ' ; }
In contrast with isset empty, empty ($ arr [ 'foo']) corresponds! isset ($ arr [ 'foo']) || $ arr [ 'foo'] == false
<? PHP $ ARR = Array ( ' Hello ' => ' Hello ' , ' Pink ' => ' pink ' , ' Blue ' => ' blue ' , ); IF (empty (ARR $ [ ' foo ' ] )) { echo ' no ' ; } the else { echo $ ARR [ ' foo ' ]; }