爆炸不适用于字符串内的多重逗号 [英] Explode does not work with multilpe commas inside the string
问题描述
为什么当我尝试爆炸字符串时它不起作用?
$ Text =巴西,银行,家庭,英国,,,,测试,财务时间,。,ipad ,,银行,两个字,,;
$ Text_Array = explode(,,$ Text);
$ Text_Array = array_filter($ Text_Array);
print_r($ Text_Array);
我希望将所有标记除以一个逗号,并删除任何空格和重复的标记。 / p>
我希望得到这样的结果: b brazil,banks,home,uk ,测试,财务时间,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? 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 Note .. Please this would not remove the Output
这篇关于爆炸不适用于字符串内的多重逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b
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,两字
$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);
remove any space and duplicate tags
then you need to also add array_unique
with array_filter
$textAray = array_unique(array_filter($textAray));
.
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);
brazil,banks,home,uk,test,financial times,ipad,Two words