加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP 将逗号、空格、回车分隔的字符串转换为一个数组的函数

发布时间:2023-02-28 13:20:57 所属栏目:PHP教程 来源:
导读:<?PHP

/**

* transform &#39; hello,world !&#39; to array(&#39;hello&#39;,&#39;world&#39;)

*/

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)); 

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章