-
- /**
- * 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));
- ?>
Copy code
Articles you may be interested in:
Example of php space-separated text into array
A simple example of splitting a Chinese string into an array in php
Several ways to split Chinese and English strings in php
php split() string splitting function application example
Solution to php splitting GBK Chinese garbled characters
Example of php string splitting function explode
|