Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function getUrlParams($route){
$params = explode("/", $route);
array_shift($params);
array_pop($params);
$url = "";
foreach($params as $param){
if($param === 'price'){
break;
}
$url = $url . $param . '/';
//echo $url . "\n";
}
echo $url;
return [
'url' => '/' . $params[1] . '/' . $params[2] . '/',
'c' => end($params),
];
}
/*
*Тесты
*/
$route = "/catalog/tovarurl/price/2578/";
$route2 = "/catalog/aaaaxxxxssx/yydyd/price/2578/";
print_r(getUrlParams($route));
print_r(getUrlParams($route2));