分隔空格分隔的单词并删除重复的单词
我在 php 中发现了 preg_split 和 explode 函数,用于将空格分隔的字符串分解为单词。它也很有用。但我想要的下一步是删除重复的单词和 [",","."还有其他一些标点符号]...
就像 if
“我爱尼泊尔。尼泊尔是一个内陆国家。尼泊尔位于亚洲。”
我只想在句子中获得独特的单词,例如:
我爱尼泊尔,是亚洲的一个内陆国家
I found preg_split and explode functions in php for breaking space seperated string into words. its quite useful too. but the next step i would like to work is remove the duplicate words and [",","." and few other punctuation marks ] too...
like if
"I love nepal. Nepal is a landlocked country. Nepal is in Asia."
I would like to get only unique words in the sentance like:
I, love, nepal, is, a, landlocked, country, in, Asia
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://php.net/manual/en/function.array-unique.php
http://php.net/manual/en/function.array-unique.php
这应该可以完成工作:
This should just about get the job done: