I need to repeatedly remove certain stop words from articles. Currently I am using the function str_replace to achieve this. As the first argument I use the stop list array
You need to instead use preg_replace with word boundaries. For example below we're only replacing word the while avoiding replacing them or then etc
the
them
then
$string = preg_replace('/\bthe\b/', '', $string);