Php converts a string separated by commas, spaces, and carriage return to an array.
- /**
- * Transform 'Hello, world! 'To array ('hello', 'World ')
- * Url: http://bbs.it-home.org
- * Date: 2013/2/17
- */
- Function strsToArray ($ strs ){
- $ Result = array ();
- $ Array = array ();
- $ Strs = str_replace (',', $ strs );
- $ Strs = str_replace ("n", ',', $ strs );
- $ Strs = str_replace ("rn", ',', $ strs );
- $ Strs = str_replace ('', ',', $ strs );
- $ Array = explode (',', $ strs );
- Foreach ($ array as $ key => $ value ){
- If (''! = ($ Value = trim ($ value ))){
- $ Result [] = $ value;
- }
- }
- Return $ result;
- }
- // Test http://bbs.it-home.org
- $ Strs = 'code is poetry! WTF! ';
- Var_dump (strsToArray ($ strs ));
- ?>
Articles you may be interested in: examples of php space-separated text as an array php simple example of splitting Chinese strings as an array php several methods of splitting Chinese and English strings php split () application example of string segmentation function php segmentation GBK Chinese garbled solution example of php string segmentation function explode |