how to create this array?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
moallemi
Forum Newbie
Posts: 2
Joined: Wed Oct 15, 2008 11:28 am

how to create this array?

Post 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 
        ) 
 
)
 
Last edited by onion2k on Fri Oct 17, 2008 3:52 am, edited 1 time in total.
Reason: Please don't post in bold. It's really annoying.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to create this array?

Post by requinix »

This is better suited for the regex forum. Which you already posted in.
Post Reply