PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?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));
Show:  
Copy Clear