views:

43

answers:

2

Hi folks

Looking for suggestions as to the best way to do this (I know there are many options):

take a variable like this:

$args = ('post_type=post&order_by=DESC&limit=10');

the create a function to convert that variable into parts like this:

$post_type = post;
$order_by = DESC;
$limit= 10;

Reason is I want a client to be able to use a string like the first to pass variables to a sql query in much the same way (but doesn't have to be exact) as you can do it in WordPress.

+2  A: 

You might want to take a look at

http_build_query()

and

parse_str() ( in your case it's more parse_str() but you'll need the first one for "doing the opposite" )

Kemo
Thanks kemo, totally forgot parse_str() - durrrr.
RussP
+1  A: 

I think the parse_str function can help you.

$query = parse_str($args);
$post_type = $query['post_type'];
$order_by = $query['order_by'];
$limit = $query['limit'];
Vincent Robert