doutizha7526 2017-08-30 17:44
浏览 38
已采纳

为什么停止删除单词是空的? (PHP)

I'm the beginner NLP programmer in PHP. I just want to discuss about the stop word removal.

this is my practice:

I have the following declaration of a variable $words = "he's the young man";

and then I remove the common words like this

 $common_words = $this->common_words();
 $ncwords = preg_replace('/\b('.implode('|',$common_words).')\b/','',$data); 
 // I have save the array common_words in another function

and I explode my no common words

$a_ncwords=explode(" ", $ncwords);

But, when I print $a_ncwords, like so print_r($a_ncwords);

I get a result like this:

Array ( [0] => [1] => [2] => young [3] => man )

why are the index[0] and index[1] array values null?

  • 写回答

2条回答 默认 最新

  • dongyangzhi0687 2017-08-30 17:48
    关注

    Remove the empty array elements.

    To appease those who said it didn't answer your question:

    Your preg_replace is replacing words with null and when you explode because your regex is off, those null values are getting created in your array $a_ncwords when you explode.

    $a_ncwords = array_filter($a_ncwords);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Fluent udf 编写问题
  • ¥15 求合并两个字节流VB6代码
  • ¥15 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题
  • ¥15 海湾GST-DJ-N500
  • ¥15 氧化掩蔽层与注入条件关系
  • ¥15 Django DRF 如何反序列化得到Python对象类型数据
  • ¥15 多数据源与Hystrix的冲突