From 7ad08b65707f27de8b0a8a218b070c402c961a5e Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 6 Feb 2005 07:32:11 +0000 Subject: [PATCH] r48: FINALLY got regex matching for PCV splits to work! --- includes/functions.php | 67 +++++++++--------------------------------- 1 file changed, 14 insertions(+), 53 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 1445d9c..7f63742 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -380,65 +380,26 @@ function parse_pcv_select($input) { $input = trim($input); - ///////// PREG_MATCH IS A PIECE OF SHIT!1!!!!11! - // (yes I just swore in the code because the bastard of a RegEx didn't match - // my string for any good reason) - //var_dump( preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) ); - /*if (ereg('p[:digit:].+?c[:digit:].+?v[:digit:].+?', $input) === false) + /* + yummy regex tests.... + var_dump(preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input)); + var_dump(preg_match('#^p(\d.+?)c(\d.+?)v(\d.+?)$#', $input)); + var_dump(preg_match('#^p([0-9]+?)c([0-9]+?)v([0-9]+?)$#', $input)); + var_dump(preg_match('#^p([0-9].+?)c([0-9].+?)v([0-9].+?)$#', $input)); + */ + + if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0) { return false; - }*/ - - - /////////// CANT'T EXPLODE EMPTY - //$moo = explode('', $input); - //print_r($moo); - - - /////////// TOKENIZING TAKES WAAAAAAAAAAY TOO MUCH WORK - /*$tokens = array('p', 'c', 'v'); - $token = current($tokens);*/ - /*for ($i = 0; $i <= strlen($input); $i++) - { - $char = $input[$i]; - echo $token . "-$i>$char "; - if (is_numeric($char)) - { - $trio["$token"] .= $char; - } - else - { - array_shift($tokens); - $token = current($tokens); - if ($char != $token AND $char != current($tokens)) - { - // return false; - } - } - }*/ - - ///////// TOKENIZING 2 -- NO WORKEY - /*foreach ($tokens AS $token) - { - for ($i = 0; $i <= strlen($input); $i++) - { - $char = $input["$i"]; - if ($char != current($tokens)) - { - - } - } - }*/ - - //////// SO WE DO IT THE MORONIC WAY AND IT WORKS!!!! - $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); - print_r($trio); - if (count($trio) != 6 OR $trio[0] != 'p' OR $trio[2] != 'c' OR $trio[4] != 'v') + } + + $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY); + if (count($trio) != 3) { return false; } - return array('product' => intval($trio[1]), 'component' => intval($trio[3]), 'version' => intval($trio[5])); + return array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2])); } /*=====================================================================*\ -- 2.22.5