Page 1 of 1

Advanced query Engine With Regex

Posted: Wed Oct 15, 2008 11:46 am
by moallemi
I want to create a query engine that parse an input string and give me a standard array, then i create sql query from that, but i have problem with regex!

can anybody help me?

my input string can be in one of these formats:

Code: Select all

 
//format #1
$string = "keyword1 keyword2 source:src1,src2 with space,src3 category:cat1,cat2";
 
//format #2
$string = "keyword1 keyword2 category:cat1,cat2 source:src1,src2 with space,src3";
 
i want to parse these string and get this array with regex:

Code: Select all

 
Array 
( 
    [keyword] => Array 
        ( 
            [0] => keyword1 
            [1] => keyword2 
        ) 
 
    [source] => Array 
        ( 
            [0] => src1 
            [1] => src2 with space 
            [2] => src2 
        ) 
    [category] => Array 
        ( 
            [0] => cat1 
            [1] => cat2 
        ) 
 
)