爆炸不适用于字符串内的多重逗号 [英] Explode does not work with multilpe commas inside the string

查看:120
本文介绍了爆炸不适用于字符串内的多重逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为什么当我尝试爆炸字符串时它不起作用?

  $ Text =巴西,银行,家庭,英国,,,,测试,财务时间,。,ipad ,,银行,两个字,,; 

$ Text_Array = explode(,,$ Text);

$ Text_Array = array_filter($ Text_Array);

print_r($ Text_Array);

我希望将所有标记除以一个逗号,并删除任何空格和重复的标记。 / p>

我希望得到这样的结果: b
$ b

brazil,banks,home,uk ,测试,财务时间,ipad,两个字;

请问,你能帮我实现这个目标么?

删除任何空格和重复标签,那么你还需要添加 array_unique code> with array_filter

  $ textAray = array_unique(array_filter ($ textAray)); 

注意 ..请不要删除在结果中..这是一个更好的方式来过滤结果

  $ text = 巴西,银行,家,英国,,,,测试,财务时间,。,iPad,银行,两个字,; 
$ textArray = array_unique(preg_split(/[,.]+/,$ text));
$ textArray = array_filter($ textArray);
echo implode(,,$ textArray);

输出

 巴西,银行,家庭,英国,测试,财务时间,ipad,两字


I try to find the answer here and in Google but no luck!

Why it does not work when I try to explode the string?

$Text = "brazil,banks,home,,uk,,,,test,financial times,.,ipad,,banks,,Two words,,";

$Text_Array = explode(",",$Text);

$Text_Array = array_filter($Text_Array);

print_r($Text_Array);

I would like to have all my tags divide by ONE comma and remove any space and duplicate tags.

I would like this result:

"brazil,banks,home,uk,test,financial times,ipad,Two words";

Please, can you help me to achieve this?

解决方案

If you want to remove any space and duplicate tags then you need to also add array_unique with array_filter

$textAray = array_unique(array_filter($textAray));

Note .. Please this would not remove the . in the result .. here is a better way to filter your results

$text = "brazil,banks,home,,uk,,,,test,financial times,.,ipad,,banks,,Two words,,";
$textArray = array_unique(preg_split("/[,.]+/", $text));
$textArray = array_filter($textArray);
echo implode(",", $textArray);

Output

brazil,banks,home,uk,test,financial times,ipad,Two words

这篇关于爆炸不适用于字符串内的多重逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆