PHP Class 8 common functions for string splitting and php string splitting
Course Overview:
This lesson allows you to perform basic operations on strings.
String knowledge point:
1. Introduction to string processing
2. Common string Output Functions
3. common string formatting Functions
4. String comparison functions
5. Application of Regular Expressions in strings
6. Regular Expressions used with per1
1. pathinfo (); // return the path information of the domain name
2. parse_url ();
3. parse_str (); // used to split Parameters
Pathinfo ();
<?php$str="http://blog.csdn.net/junzaivip";$arr = pathinfo($str);echo "<pre>";print_r($arr);echo "</pre>";?>
// Split a domain name into an array
<?php$str="http://blog.csdn.net/junzaivip.php?id=10&name=20";$arr = parse_url($str);$query = $arr['query'];$arr2 = explode("&",$query);foreach ($arr2 as $val) {$arr3 = explode("=", $val);foreach ($arr3 as $value) {$arr4[$arr3[0]] = $arr3[1]; }}echo "<pre>";print_r($arr4);echo "</pre>";?>
// Obtain the same method
<?php$str="http://blog.csdn.net/junzaivip.php?id=10&name=20";$arr= parse_url($str);parse_str($arr['query'],$arr4);echo "<pre>";print_r($arr4);echo "</pre>";?>
// Method 3
<?php$str="http://blog.csdn.net/junzaivip.php?id=10&name=20";$arr= parse_url($str);$arr2 = preg_split('/&|=/', $arr['query']);//echo count($arr2);for ($i=0; $i < count($arr2); $i++) { $arr3[$arr2[$i]] = $arr2[++$i];}echo "<pre>";print_r($arr3);echo "</pre>";?>
String knowledge point:
1. Introduction to string processing
2. Common string Output Functions
3. common string formatting Functions
4. String comparison functions
5. Application of Regular Expressions in strings
6. Regular Expressions used with per1
String Functions
Echo
Print
Printf (); Direct output
Sprintf (); returns directly
String connector:
. Use point connection
Print "aaaaaaaaaa ";
Printf ("---- % s -- $ s --", $ a, $ B );
% S string
% D Number
% F floating point (%. 2f indicates two digits after the decimal point)
Sprintf (); no direct output. A new variable is returned.
Common string formatting functions:
1. Remove spaces and strings to fill the Function
1. ltrim (); // remove the left space
2. rtrim (); // remove the right space
3. trim (); // remove spaces on both sides
4. str_pad (); // used to fill in spaces or customize characters to specify the length
5. str_repeat (); // used to repeat the previous character (used to create an unlimited category menu)
6. strlen () // obtain the string length
Echo "|". str_repeat ("-", 5). "bb ";
String case Conversion Function
1. strtoupper (); // convert all to uppercase
2. strtolower (); // convert all to lowercase letters
3. ucfirst (); // uppercase letters
4. ucwords (); // uppercase letters of each letter
Other string formatting functions:
1. strlen (); // String Length
2. strrev (); // string flip
3. number_format (); // numeric character Function
4. md5 // md5 encrypted string, 32-Bit String
5. str_shuffle (); randomly breaks the string and the number of digits remains unchanged.
String functions:
String functions associated with html:
1. nl2br (): converts/n to a br tag.
2. htmlspecialchars (); Convert object
'"<> & Convert to entity
& Quot: indicates an object.
& Lt: Yu no.
& Gt: greater
3. addslashes () // '"\ add in front \ to reduce damage to the database
4. Remove the \ above stripslashes () // '"\
3. strip_tags (); only some labels are retained and the labels you want to remove are removed.
Note: We recommend that you control the database before it is inserted into the database.
1. [B] [/B] only convert limited tags for tag Filtering
2. addslashes ();
'"" \ Add in front \ to reduce damage to the database
3. htmlspecialchars ()
'"<> & Convert to an object to prevent the database from becoming any faster
Php split string
Use the explode Function
$ Str = "Gender: female <br> Age: 40 <br> Hi, I'm bloating. I have a very fast bowel movement, so I just can't get down. It is also very detailed. What is going on <br>
Reply 1: Hello, you are suffering from constipation. We recommend that you eat more vegetables and bananas to develop the daily stool habit.
Reply 2: this may be due to impaired gastrointestinal function. It may be caused by the use of Xisha Billy muxiang shunqi pill for conditioning treatment.
";
$ Arr = explode ("<br>", $ str );
Print_r ($ arr );
PHP string splitting
Explode (separator, string, limit)
Separator is required. Specifies where to split the string.
String is required. The string to be split.
Limit is optional. Specifies the maximum number of returned array elements.