<?php
$page_key ='C=calendar&A=etoyear#month=12&year=2018&third=test';
$res = analyzePagekey($page_key);
var_dump($res);
function analyzePagekey($key){
$page_info_arr = null;
define('PAGE_KEY_DELIMITER','#');//TODO
define('PAGE_KEY_DELIMITER2','&');//TODO
define('PAGE_KEY_DELIMITER3','=');//TODO
define('PREFIX_CONTROLLER','C=');//TODO
define('PREFIX_ACTION','A=');//TODO
if(empty($key)){
return false;
}
//C=calendar&A=etoyear#year=2018
$fun_params_arr = explode(PAGE_KEY_DELIMITER,$key);
//controllerとactionを含む文字列(例:C=calendar&A=etoyear)
$fun_str = $fun_params_arr[0];
//controlとaction配列
$fun_arr = explode(PAGE_KEY_DELIMITER2,$fun_str);
//controller(例:C=calendar)
$page_info_arr['controller'] = str_replace(PREFIX_CONTROLLER,'',$fun_arr[0]);
//action(有りの場合。例:A=etoyear)
$page_info_arr['action'] = count($fun_arr)>1 ? str_replace(PREFIX_ACTION,'',$fun_arr[1]) : null;
//パラメータを含む文字列(例:year=2018&month=12)
$parmas_str = count($fun_params_arr) > 1 ? $fun_params_arr[1] : null;
//パラメータ配列
$params_arr = explode(PAGE_KEY_DELIMITER2,$parmas_str);
foreach($params_arr as $k => $v){
$param_key = explode(PAGE_KEY_DELIMITER3,$v)[0];
$param_val = explode(PAGE_KEY_DELIMITER3,$v)[1];
$page_info_arr['params'][$k] = array('key'=>$param_key,'value'=>$param_val);
}
return $page_info_arr;
}
?>