regex to replace a given word with space at either side or not at all

前端 未结 4 1054
后悔当初
后悔当初 2021-01-21 18:48

I am working with some code in PHP that grabs the referrer data from a search engine, giving me the query that the user entered.

I would then like to remove certain stop

4条回答
  •  余生分开走
    2021-01-21 19:40

    $keywords = "...";
    $stopWords = array("for","sale");
    foreach($stopWords as $stopWord){
        $keywords = preg_replace("/(\b)$stopWord(\b)/", "", $keywords);
    }
    

提交回复
热议问题