router
/
t.php
16 строк · 298.0 Байт
1<?php
2
3
4$route = '/post/{type}/{id}';
5
6$result = preg_replace_callback('~{[^}]+}~', function ($matches) {
7
8$name = trim($matches[0], '{}');
9
10return '(?<' . $name . '>.*)';
11
12}, '/post/{type}/{id}');
13
14$matches = [];
15preg_match('~'.$result.'~', '/post/media/10', $matches);
16print_r($matches);
17