Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /bapple|bbanana|bstrawberry|bpear.*?bcake|bcake.*?bpear/
- <?php
- function permutations($array)
- {
- $list = array();
- for ($i=0; $i<=10000; $i++) {
- shuffle($array);
- $tmp = implode(',',$array);
- if (isset($list[$tmp])) {
- $list[$tmp]++;
- } else {
- $list[$tmp] = 1;
- }
- }
- ksort($list);
- $list = array_keys($list);
- return $list;
- }
- function CreateRegex($array)
- {
- $toReturn = '/';
- foreach($array AS $value)
- {
- //Contains spaces
- if(strpos($value, " ") != false)
- {
- $pieces = explode(" ", $value);
- $combos = permutations($pieces);
- foreach($combos AS $currentCombo)
- {
- $currentPieces = explode(',', $currentCombo);
- foreach($currentPieces AS $finallyGotIt)
- {
- $toReturn .= 'b' . $finallyGotIt . '.*?';
- }
- $toReturn = substr($toReturn, 0, -3) . '|';
- }
- }
- else
- {
- $toReturn .= 'b' . $value . '|';
- }
- }
- $toReturn = substr($toReturn, 0, -1) . '/';
- return $toReturn;
- }
- var_dump(CreateRegex(array('apple', 'banana', 'strawberry', 'pear cake')));
- ?>
Add Comment
Please, Sign In to add comment