I have following URL string
/category/category1/2010/12/10/id
I need to separate string into parts. I'm trying this pattern
(?:(.*))?(?:(?:\/)?([0-9]{4}))?(?:(?:\/)?([0-9]{1,2}))?(?:(?:\/)?([0-9]{1,2}))?(?:(.*))?
but it doesn't work properly
if URL is like this /category/category1/, I need the following vars
path = '/category/category1/';
year = '';
month = '';
day = '';
id ='';
if URL is like this /category/category1/2010, I need the following vars
path = '/category/category1/2010';
year = '2010';
month = '';
day = '';
id ='';
if URL is like this /category/category1/2010/12/, I need the following vars
path = '/category/category1/2010/12';
year = '2010';
month = '12';
day = '';
id ='';
if URL is like this /category/category1/2010/12/10, I need the following vars
path = '/category/category1/2010/12/10';
year = '2010';
month = '12';
day = '10';
id ='';
if URL is like this /category/category1/2010/12/10/id, I need the following vars
path = '/category/category1/2010/12/10/id';
year = '2010';
month = '12';
day = '10';
id ='id';
Is it possible to make this with preg_match and regex?
/category/category1/idor any other combination you didnt list? Why not just use plain old query strings instead, e.g.?category=1&d=2010-12-10&id?