Skip to content

Instantly share code, notes, and snippets.

@sam-ngu
Created August 24, 2020 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sam-ngu/6c4d527af205d43e2ff02ff93f342381 to your computer and use it in GitHub Desktop.
Save sam-ngu/6c4d527af205d43e2ff02ff93f342381 to your computer and use it in GitHub Desktop.
Parsing URL parameter name using Symfony Route.
<?php
$uri = 'https://test.com/api/users/{user}?page=4&size=5';
$route = new SymfonyRoute(
preg_replace('/\{(\w+?)\?\}/', '{$1}', $uri), [], [], ['utf8' => true, 'action' => []],
'', [], []
);
$compiled = $route->compile();
// getting the variables as an array
$variables = $compiled->getVariables();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment