Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Max Possible Combination(s) Generator</title>
- <style type="text/css">
- body {background-color: black;}
- h1 {font-family: monospace; color: white;}
- </style>
- </head>
- <body>
- <center>
- <h1>~ Max Possible Combination(s) Generator ~</h1>
- <form method="POST">
- <input type="text" name="comb" />
- <font face="Monospace" color="lime"> ~ </font>
- <input type="submit" value="Generate" />
- </form>
- <?php
- /*
- Credits for the function goes to, Joel Hinz.
- http://stackoverflow.com/questions/19067556/php-algorithm-to-generate-all-combinations-of-a-specific-size-from-a-single-set
- */
- function combinations($chars, $size, $combinations = array())
- {if (empty($combinations)) {$combinations = $chars;}
- if ($size == 1) {return $combinations;}
- $new_combinations = array();
- foreach ($combinations as $combination) {
- foreach ($chars as $char) {
- $new_combinations[] = $combination . $char;}}
- return combinations($chars, $size - 1, $new_combinations);}
- $chars = $_POST['comb']; # The Post Param
- $count = 1; # Duuuh :v
- if (isset($chars)){
- $strspl = str_split($chars); # To get every 'char' from the param.
- $strlen = strlen($chars); # To get the length of the str from the param
- $result = combinations($strspl, $strlen); # Runnin the function
- echo '<br><font face="Monospace" color="white">Total Possible Combinations<font color="lime"> ~ <font color="red">'.count($result).'<br>'; # Echoing the count of combinations.
- foreach ($result as $r) { # Foreach statement to echo the "result"
- echo '<font color="white">'.$count++.' <font color="lime">~<font color="red"> '.$r.'<br>'; # the final result
- }}
- ?>
- </center>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement