zoombie Posted April 7, 2021 Share Posted April 7, 2021 Hi all dear can anyone help me how to find all permutation of a String by allow user input text or number and generate when user click on button, user need to input text on number in input box and click generate button to show result of all permutation of a String below is code i found from https://www.journaldev.com/526/permutation-of-string-in-java but it's not allow user input text, please help me in php function thank with best regard <!DOCTYPE html> <html> <body> <?php function generatePermutation($string,$start,$end){ if($start == $end-1){ echo "$string - "; } else{ for($i = $start; $i < $end; $i++){ $temp = $string[$start]; $string[$start] = $string[$i]; $string[$i] = $temp; generatePermutation($string,$start+1,$end); $temp = $string[$start]; $string[$start] = $string[$i]; $string[$i] = $temp; } } } $str = "ABC"; $n = strlen($str); echo "All the permutations of the string are: "; generatePermutation($str,0,$n); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/312436-how-to-find-all-permutation-of-a-string-by-allow-user-input-text-or-number/ Share on other sites More sharing options...
NotSunfighter Posted April 7, 2021 Share Posted April 7, 2021 You need to generate an HTML page with an INPUT for the user generated string then use a JAVASCRIPT function called Ajax to transfer user input to your PHP function and transfer the permutations back to JS to show them. Quote Link to comment https://forums.phpfreaks.com/topic/312436-how-to-find-all-permutation-of-a-string-by-allow-user-input-text-or-number/#findComment-1585648 Share on other sites More sharing options...
zoombie Posted April 8, 2021 Author Share Posted April 8, 2021 10 hours ago, NotSunfighter said: You need to generate an HTML page with an INPUT for the user generated string then use a JAVASCRIPT function called Ajax to transfer user input to your PHP function and transfer the permutations back to JS to show them. Thank you so much for your reply, can you help me with code, i don't know how to do it, please kindly help me with example code please dear thank with best regard Quote Link to comment https://forums.phpfreaks.com/topic/312436-how-to-find-all-permutation-of-a-string-by-allow-user-input-text-or-number/#findComment-1585657 Share on other sites More sharing options...
zoombie Posted April 9, 2021 Author Share Posted April 9, 2021 Dear please kindly help me 🙏 I need it for lottery, allow user to auto random their lucky number please help me dear Quote Link to comment https://forums.phpfreaks.com/topic/312436-how-to-find-all-permutation-of-a-string-by-allow-user-input-text-or-number/#findComment-1585670 Share on other sites More sharing options...
NotSunfighter Posted April 9, 2021 Share Posted April 9, 2021 Here a solution from Stackoverflow <!DOCTYPE html> <html lang="en"> <head></head> <body> <script> var permArr = [], usedChars = []; str = [5,3,7,1]; function permute(input) { var i, ch; for (i = 0; i < input.length; i++) { ch = input.splice(i, 1)[0]; usedChars.push(ch); if (input.length == 0) { permArr.push(usedChars.slice()); } permute(input); input.splice(i, 0, ch); usedChars.pop(); } return permArr }; document.write(JSON.stringify(permute(str))); STACKOVERFLOW </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/312436-how-to-find-all-permutation-of-a-string-by-allow-user-input-text-or-number/#findComment-1585676 Share on other sites More sharing options...
zoombie Posted April 16, 2021 Author Share Posted April 16, 2021 str = [5,3,7,1]; this string should be input by user and generate only when user click on generate button to show result Quote Link to comment https://forums.phpfreaks.com/topic/312436-how-to-find-all-permutation-of-a-string-by-allow-user-input-text-or-number/#findComment-1585855 Share on other sites More sharing options...
zoombie Posted April 16, 2021 Author Share Posted April 16, 2021 https://www.sanfoundry.com/java-program-permute-all-letters-input-string/ I don't know how to do it with this Quote Link to comment https://forums.phpfreaks.com/topic/312436-how-to-find-all-permutation-of-a-string-by-allow-user-input-text-or-number/#findComment-1585856 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.