spires Posted June 10, 2011 Share Posted June 10, 2011 Hi I'm trying to build a system that will allow me to too for a sting with in a string. But, in any order. E.G: hire bartender Will bring back - hire bartender - hire a bartender - bartender hire - bartender for hire - hire bartenders - hire a bartenders - bartenders hire - bartenders for hire Currently, it only returns: - hire bartender - hire bartenders Any ideas? $key = $_POST['key']; $ad = $_POST['ad']; $expKey = explode("<br />", nl2br($key)); $expAd = explode("<br />", nl2br($ad)); foreach($expAd as $expAds){ foreach($expKey as $expKeys){ if(strstr($expKeys, $expAds)){ $keyList .= $expKeys; } } $keyList .= "\n"; } Link to comment https://forums.phpfreaks.com/topic/239015-string-with-in-a-string/ Share on other sites More sharing options...
spires Posted June 10, 2011 Author Share Posted June 10, 2011 ok solved it. Here is the answer for anyone how wants to know: Basically, had to separate all the words and look one by one. $key = $_POST['key']; $ad = $_POST['ad']; $expKey = explode("<br />", nl2br($key)); $expAd = explode("<br />", nl2br($ad)); $a=0; foreach($expAd as $expAds){ $expAd2 = explode(" ", $expAds); $b=0; foreach($expKey as $expKeys){ $expKey2 = explode(" ", $expKeys); for($c=0;$c<count($expKey2);$c++){ if(strpos($expKey2[$c], $expAd2[$a])){ $keyList .= $expKeys; } } $b++; } $keyList .= "\n"; $a++; } Link to comment https://forums.phpfreaks.com/topic/239015-string-with-in-a-string/#findComment-1228093 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.