Saruman Saruman - 1 year ago 62
PHP Question

GET request array from .htaccess to php file

I have a small problem.
Lets say we have the following lines in our .htaccess file:

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

When I get the URL in index.php, its basically:


If i were to send an array as the 3th argument, how do I cast it to a PHP array:


This will get routed to my function which might look like this:

public function api($first, array $second, $third) {}

I don't want to call it like


So how do I extract the array from the URL if I know that the 2 argument should be an array?

Is there a built-in function for this or should i perhaps rewrite my routing? :)

Answer Source

Php uses the ampersand to separate query paramteres.

Your also missing the "?" Which indicates you have parameters.



With the new edit, you can use parse_str to convert your second argument to an array. This would be done in your router.

Parses str as if it were the query
string passed via a URL and sets 
variables in the current scope.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download