: This article describes how to process strings in php. For more information about PHP tutorials, see. 1. get the string length
$ Str = 'abc'; $ str1 = 'Chinese'; echo strlen ($ str ),'
', Strlen ($ str1); output result: 36
2. search for strings
// Locate the first occurrence of a string $ char = 'a'; $ str = 'abc'; $ bRet = strpos ($ str, $ char ); if ($ bRet = false) {echo "$ str does not contain $ char";} else {echo "$ str contains $ char";} echo'
'; Output result: abc contains
3. replace string
// Replace string str_replace () $ str = 'good morning'; $ str1 = str_replace ('moring', 'afternoon', $ str); echo $ str ,'
', $ Str1; output: Good morningGood morning // replace string strtr () $ str =' get on the bus, go to work, get off, get off class, get off work '; $ str1 = strtr ($ str, ['Up' => 'down', 'down' => 'Up']); echo $ str ,'
', $ Str1; output result: boarding, attending, getting to work, getting off, getting on, going to work
4. truncate a string
// Truncate the string substr (). The parameters are the target string, starting position, and the truncate length $ str = 'East, west, home is best'; echo $ str ,'
', Substr ($ str,); output result: East, west, home is bestEast
5. split the string
// Split string explode () $ str = 'Cook, play, and play sub'; $ arr = explode (',', $ str); echo $ str ,'
'; Print_r ($ arr); output result: cook, play, and recipe Array ([0] => Cook [1] => play [2] => Cook)
6. Merge arrays into strings
$ Arr = ['0' => 'cook sub', '1' => 'player', '2' => 'cook sub']; $ str = implode ($ arr, ';'); print_r ($ arr); echo'
'; Echo $ str; output result: Array ([0] => Cook [1] => play [2] => Cook) cook, play, and Cook
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above describes the php processing string, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.