时间:2021-07-01 10:21:17 帮助过:6人阅读
/**
* transform ' hello, world !' to array('hello', 'world')
*/
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
$strs = 'Code is poetry! WTF!';
var_dump(strsToArray($strs));
http://www.bkjia.com/PHPjc/325599.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325599.htmlTechArticle我们在搜索一些东西时会经常遇到可以通过空格隔开来达到输入多个条件的目的。今天正好项目中遇到了这个情况,就写了一个函数,将多...