What would be the best, simplest way to code this: I have a php document that gets most of the page requests (set up in routes config, using code igniter framework) and depending on the uri i want to show the user different content. Example:
http: // domain.tld/2010/
Should show one type of content
http: // domain.tld/2010-nov/
should show another type of content
http: // domain.tld/2010-nov-10/
should show yet another type of content
http: // domain.tld/2010-nov-10-blog-post-title/
should show once again another type of content
Everything else should be treated as if is a product, example:
http: // domain.tld/light-bulb/
and if such a product doesnt exist, its a 404
Below is the code I got at the moment, but I feel it is way too messy. Any suggestion how to make it simpler and more effective? (Tried to get it formatted correctly here but it seem a bit tricky to get code to align properly, a apologize)
Regards,
Jason
(had to add spaces in all my urls here because im new and not allowed to post that many urls)
$val is the uri (/2010-nov.......)
function show_what($val){
$arr=array("jan"=>01,"feb"=>02,"mar"=>03,"apr"=>04,"may"=>05,"jun"=>06,"jul"=>07,"aug"=>08,"sep"=>09,"oct"=>10,"nov"=>11,"dec"=>12);
// first check to see if the uri starts with a year (4 digits)
if(is_int((int)substr($val,0,4)) && (int)substr($val,0,4)!=0){
// Get all posts for specified YEAR
if(strlen($val)==4){
// Show all blog posts for specified year
// example: http: // domain.tld/2010/
// Get all posts for specified YEAR and MONTH
}elseif(strlen($val)==8 && substr($val,4,1)=="-" && array_key_exists(substr($val,5,3),$arr)){
// show all blog posts for specified year and month
// example: http: // domain.tld/2010-nov/
// Get all posts for specified YEAR, MONTH and DAY OR! get specified post
}elseif(strlen($val)>=11 && substr($val,4,1)=="-" && array_key_exists(substr($val,5,3),$arr) && substr($val,8,1)=="-" && is_int((int)substr($val,9,2)) && (int)substr($val,9,2)!=0){
// Get all posts for specified YEAR, MONTH and DAY
if(strlen($val)==11){
// show all blog posts for specified year, month and day
// example: http: // domain.tld/2010-nov-10/
// Get specified post
}elseif(substr($val,11,1)=="-"){
// show specified post or 404
// example: http: // domain.tld/2010-nov-10-blog-post-title/
}else{
// "Not a valid article url<Br/>";
// example: http: // domain.tld/2010-nov-10there-is-a-dash-missing-after-day/
}
}else{
// 404, not a real date
}
}else{
// show product with current uri or if it doesnt exist, 404.
}
}