PHP 将逗号、空格、回车分隔的字符串转换为一个数组的函数
发布时间:2023-02-28 13:20:57 所属栏目:PHP教程 来源:
导读:<?PHP
/**
* transform ' hello,world !' to array('hello','world')
*/
function strsToArray($strs) {
$result = array();
$array = array();
$strs = str_r
/**
* transform ' hello,world !' to array('hello','world')
*/
function strsToArray($strs) {
$result = array();
$array = array();
$strs = str_r
|
<?PHP /** * 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)); (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
