本程序用来获取一个网站的meta keyword信息,keyword通常为逗号,空格,|,分割,本函数可以把每个关键词存在数组里
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?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)); |
转载请注明:天狐博客 » PHP将逗号,空格,回车, |,分隔的字符串转换为数组