Code: Select all
<?php
$common_words = "to, this, all, the, from";
$sentence = "I want to remove all the common words from this sentence";
?>"I remove common words sentence."
Moderator: General Moderators
Code: Select all
<?php
$common_words = "to, this, all, the, from";
$sentence = "I want to remove all the common words from this sentence";
?>Code: Select all
$sentence = preg_replace('/\s*('.preg_replace(array('/,/','/\s+/'),array('|',''),$common_words).')\s*/i',' ',$sentence);Code: Select all
echo str_replace(explode(",", $common_words), '', $sentence);