If we wanted to remove some words from any string, this snippet would be helpful:

 

<?php
$searchText = "This is Cambridge History";
$stopWords = array('a', 'an', 'the', 'is', 'in', 'at', 'on', 'etc.');
$pattern = '/\b(?:' . join('|', $stopWords) . ')\b/i';
$filteredText = preg_replace($pattern, '', $searchText);
print_r($filteredText);
?>

 

Categorized in: