PHP code example of masroore / stopwords

1. Go to this page and download the library: Download masroore/stopwords library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

masroore / stopwords example snippets


$stopwords = new Kaiju\Stopwords\Stopwords();

// get the list of available languages
print_r($stopwords->getLanguages());

// load stopwords for a language
$stopwords->load('english');

// load stopwords for multiple languages
$stopwords->load(['english', 'french']);

// load stopwords for all available languages
$stopwords->load('*');

// check if the given word is a stop-word
$stopwords->isStopword('the'); // TRUE
$stopwords->isStopword('America'); // FALSE

// return a tokenized copy of the text, with stop-words and punctuation marks removed
$text = "Good muffins cost $3.88\nin New York.  Please buy me two of them.\n\nThanks!\n";
print_r($stopwords->strip($text));
// ["Good","muffins","cost","$3.88","New","York","Please","buy","two","Thanks"]

echo $stopwords->clean($text);
// "Good muffins cost $3.88 New York Please buy two Thanks"