Page 1 of 1

how to create this array?

Posted: Fri Oct 17, 2008 3:49 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 
        ) 
 
)
 

Re: how to create this array?

Posted: Fri Oct 17, 2008 4:39 am
by requinix
This is better suited for the regex forum. Which you already posted in.