tastro Posted September 1, 2011 Share Posted September 1, 2011 need to echo all word combinations from the input also lets say that someone types "this is my query" into an input fiend and this will be the input. i need the php script to echo all the possible combinations of this string. but there can be 4 words like in the example or 3 or more or less. also it should then echo something like this: this this is this is my this is my query is is my is my query is my query this my my query my query this my query this is query query this query this is query this is my + query is my this this my query is also all combinations possible, for 1 word, 2 words, ... max. words inputed. Quote Link to comment https://forums.phpfreaks.com/topic/246175-need-to-echo-all-word-combinations-from-the-input/ Share on other sites More sharing options...
WebStyles Posted September 1, 2011 Share Posted September 1, 2011 please post the code you already have along with whatever errors you're getting. Quote Link to comment https://forums.phpfreaks.com/topic/246175-need-to-echo-all-word-combinations-from-the-input/#findComment-1264249 Share on other sites More sharing options...
WebStyles Posted September 1, 2011 Share Posted September 1, 2011 here's a page explainig permutations, in this case with letters instead of words, but easy to adapt to your case. http://cogo.wordpress.com/2008/01/08/string-permutation-in-php/ Quote Link to comment https://forums.phpfreaks.com/topic/246175-need-to-echo-all-word-combinations-from-the-input/#findComment-1264257 Share on other sites More sharing options...
tastro Posted September 1, 2011 Author Share Posted September 1, 2011 please post the code you already have along with whatever errors you're getting. i don't have 1 yet. i have only 1 on how to do this with only the first 2 words. but don't know how to do it if the word count changes. thanks for the url below, i will take a look right now. Quote Link to comment https://forums.phpfreaks.com/topic/246175-need-to-echo-all-word-combinations-from-the-input/#findComment-1264265 Share on other sites More sharing options...
jamesxg1 Posted September 1, 2011 Share Posted September 1, 2011 <?php $words = explode(' ', $query); echo '<pre>' . print_r($words, true) . '</pre>'; ?> That should put you on the right track! James. Quote Link to comment https://forums.phpfreaks.com/topic/246175-need-to-echo-all-word-combinations-from-the-input/#findComment-1264273 Share on other sites More sharing options...
tastro Posted September 1, 2011 Author Share Posted September 1, 2011 i found what i searched for: http://mrphp.com.au/code/word-permutator-function thanks to the guy who showed me the word permutator so that i could find it with google easy. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/246175-need-to-echo-all-word-combinations-from-the-input/#findComment-1264280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.