我的函数不小心从字符串中删除了数字

时间:2019-06-04 21:55:04

标签: php arrays string substring

我的函数意外地从字符串中删除了数字,因为我希望它们仍然存在。我该如何更改?

必须不变的原始字符串; iPhone 7加34 GB 10英寸

echo implode(' ',array_unique(str_word_count('iPhone 7 plus 34 GB 10 inches',1)));

不幸的是,它返回: iPhone加GB英寸

1 个答案:

答案 0 :(得分:1)

您只需按照语法在字符列表中添加0..9,

echo implode(' ',array_unique(str_word_count('iPhone 7 plus 34 GB 10 inches',1,"0..9")));

Working demo

语法

str_word_count ( string $string [, int $format = 0 [, string $charlist ]] ) : mixed