分解URL参数


Explode URL parameters

我的网站上有一个搜索功能,我想制作seo友好的链接,所以我决定将GET查询字符串从:

http://example.com/search?category=example&subcategory=mycategory&region=2 //and other parameters

收件人:

http://example.com/search/{parameters}/{string-for-seo?}/{string-for-seo2?}/ //etc.

其中{parameters}是一个类似的字符串:c3s34r55p21

字符串的目的是压缩参数。

c3=类别id n.3,s34=子类别id n.34

等等。

问题是,我不知道如何将那个奇怪的字符串分解为数组来获取参数。

[
   'c' => 3
   's' => 34
   'r' => 55
]

我想这就是你想要的

$input = "c3s34r55p21";
$array = preg_match_all('/([a-z])('d*)/', $input, $matches);
/*
var_export($array);
echo "'n";
var_export($matches);
echo "'n";
*/
$result = array_combine($matches[1], $matches[2]);
var_export($result);
echo "'n";