Skip to content

Instantly share code, notes, and snippets.

@huzoorbux
Created October 3, 2019 10:55
Show Gist options
  • Save huzoorbux/6edd56e7b4716f3ecd04ef7d21016f5f to your computer and use it in GitHub Desktop.
Save huzoorbux/6edd56e7b4716f3ecd04ef7d21016f5f to your computer and use it in GitHub Desktop.
Search multiple words in a string it will return you occurred words.
<?php
function multi_pos($text,$search) {
$returnKey = array();
foreach($search as $keyword)
{
if(isset($keyword) && $keyword !="")
{
if(stripos($text, $keyword))
{
$returnKey[] = $keyword;
}
}
}
return $returnKey;
}
$intro = "I am huzoor bux from PHPLift.net website.";
$search = array("am","bux","pakistan","website");
$position = multi_pos($intro, $search);
if(count($position)>0)
{
echo implode(",", $position);
}
else
{
echo "nothing found.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment