How to make keywords from sentence using PHP | YourSite

How to make keywords from sentence using PHP

In this blog I will show you how to make keywords from sentence using PHP.

 

// functions
function php_slug($string)  
 {  
      $slug = preg_replace('/[^a-z0-9-]+/', '-', trim(strtolower($string)));  
      return $slug;  
 }
 
 
// Keyword maker
function makeKeywords($sentence)
{ 

$sentence =  strtolower($sentence);

// Remove Special Symbols from sentence
$removeSpecialSymbol = array("  ", "," ,"." ,";" ,":", "\"", "/", "'", "“","”","(",")", "!","?");
$sentence = str_replace($removeSpecialSymbol, "", $sentence );
 

// make unique array
$words = explode(' ', $sentence); 
$uniqueWords = array_unique($words); 
  

// remove set of words from sentence
$wordsToAvoid = array("its", "a", "an", "in", "of", "to", "we", "you", "be", "was", "ware", "may", "could", "should", "would", "the", "some", "shall", "show", "will", "have", "has", "been", "that", "with", "this", "that", "when", "how", "then", "than", "into", "for");

$newArray = array_diff($uniqueWords, $wordsToAvoid); 
$sentence = implode(', ',$newArray);
 

 return $sentence;
}

 

🚀 More Blogs You Might Like

Explore more articles and keep learning

Data Science Roadmap: From Complete Beginner to Job-Ready Practitioner
Data-Science
Data Science Roadmap: From Complete Beginner to Job-Ready Practitioner

Data Science Roadmap: From Complete Beginner to Job-Ready Practitioner...

👁 74 2026-07-26
Read More →
How AI Is Changing the Way Software Is Made
Data-Science
How AI Is Changing the Way Software Is Made

How AI Is Changing the Way Software Is Made...

👁 68 2026-07-26
Read More →
8 Mistakes That Quietly Slow Down Talented Developers
Personal-Development
8 Mistakes That Quietly Slow Down Talented Developers

8 Mistakes That Quietly Slow Down Talented Developers...

👁 100 2026-07-12
Read More →
Does religion teach hatred?
islam
Does religion teach hatred?

It is easy to spread hatred in the name of religion, but understanding the true message of religion is much de...

👁 575 2026-06-30
Read More →