验证输入中的过滤数字代码

I have particular structure of class in program. I was dealing with some exploits which I could not avail in that program. SO I created independent code which works fine for me.

I have written code to filter the number using class. There are many other similar filters.

While working on number filtering, I have to dealt with specific exploits. For that I created code soccussfully. Now I want to write it in my class. I did it but giving error. Did it Make any mistake in rewriting the code?

Here is the demonstration of what I wanted to implement : http://ideone.com/vxxDgG

Well my actually program looks like this:

class Phone extends Filter{ 
    function parse($text, $words){  
        $arrwords = array(0=>'zero',1=>'one',2=>'two',3=>'three',4=>'four',5=>'five',6=>'six',7=>'seven',8=>'eight',9=>'nine');
        preg_match_all('/[A-za-z]+/', $text, $matches);
        $arr=$matches[0];
        foreach($arr as $v){
            $v = strtolower($v);
            if(in_array($v,$arrwords)){
                $text= str_replace($v,array_search($v,$arrwords),$text);
            }
        }
        $resultSet = array();
        $l = strlen($text);
        foreach ($words as $word){
            $pattern = '/^(?:\((\+?\d+)?\)|(\+\d{0,3}))? ?\d{2,3}([-\.]?\d{2,3} ?){3,4}/';
            preg_match_all($pattern, $text, $matches, PREG_OFFSET_CAPTURE );
            $this->pushToResultSet($matches);
        }
        return $resultSet;
    }   
}

Here is rewritten code, the demonstrated program in ideone:

class Phone extends Filter{
    function parse($text, $words)
    {
        $arrwords = array_flip(array(0=>'zero',1=>'one',2=>'two',3=>'three',4=>'four',5=>'five',6=>'six',7=>'seven',8=>'eight',9=>'nine'));       
            $test= array();    
            foreach (explode(" ", $text) as $tocken)
            {
            $num = strtr(strtolower($tocken), $arrwords);
                if(is_numeric($num))
                    array_push($test,$tocken);
            }
        //print_r($test);
        $resultSet = array();
        $b = array();
        $pattern = '/^(?:\((\+?\d+)?\)|(\+\d{0,3}))? ?\d{2,3}([-\.]?\d{2,3} ?){3,4}/';
        foreach ($test as $value)
        {
            $value = strtolower($value);
            // Capture also the numbers so we just concat later, no more string substitution.
            $matches = preg_split('/(\d+)/', $value, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
            if ($matches)
            {
                $newValue = array();
                foreach ($matches as $word)
                {
                    // Replace if a valid word number.
                    $newValue[] = (isset($arrwords[$word]) ? $arrwords[$word] : $word);
                }
                $newValue = implode($newValue);            
                if (preg_match($pattern, $newValue))
                {
                        $b[] = $value;  
                    $this->pushToResultSet($b);
                }
            }
        }       
        //print_r($b);
        return $resultSet;
    }   
}

Does this code content any logical error. Like pushing array value mistake?

Above rewritten code gives error. As the code is not executed directly. It is being called from another file. So exact error line can not be seen.

I appreciate if someone can help me out.