Created
October 3, 2019 10:55
-
-
Save huzoorbux/6edd56e7b4716f3ecd04ef7d21016f5f to your computer and use it in GitHub Desktop.
Search multiple words in a string it will return you occurred words.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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