部分我有以下URL字符串如何URL字符串分隔成使用正則表達式
/category/category1/2010/12/10/id
我需要串分成部分。我想這個模式
(?:(.*))?(?:(?:\/)?([0-9]{4}))?(?:(?:\/)?([0-9]{1,2}))?(?:(?:\/)?([0-9]{1,2}))?(?:(.*))?
但如果URL是這樣/category/category1/
它不能正常工作
,我需要以下瓦爾
path = '/category/category1/';
year = '';
month = '';
day = '';
id ='';
如果URL是這樣/category/category1/2010
,我需要下列增值稅
path = '/category/category1/2010';
year = '2010';
month = '';
day = '';
id ='';
如果URL是這樣的/category/category1/2010/12/
,我需要以下瓦爾
path = '/category/category1/2010/12';
year = '2010';
month = '12';
day = '';
id ='';
如果URL是這樣/category/category1/2010/12/10
,我必須滿足下列條件瓦爾
path = '/category/category1/2010/12/10';
year = '2010';
month = '12';
day = '10';
id ='';
如果URL是這樣/category/category1/2010/12/10/id
,我需要以下瓦爾
path = '/category/category1/2010/12/10/id';
year = '2010';
month = '12';
day = '10';
id ='id';
是否有可能使preg_match
和正則表達式?
如果有人打電話'/分類/組別/ id'或任何其他組合你沒有什麼名單?爲什麼不使用普通的舊查詢字符串,例如'?類別= 1&d = 2010-12-10&id'? – Gordon 2011-05-14 16:33:35