展开 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";