robindean Posted March 14, 2007 Share Posted March 14, 2007 I'm still getting to know php (newbie). I need to remove zeros from a blogger generated archive script. The script receives a yyyymmdd date string, let's say it's 20070401 (next month). I'm trying to return it as 4.1.2007 but must remove the zeros first, as it currently returns 04.01.2007 ... what's the math here? - or - Do you have a better method for all of this? <bloggerarchives> $y20070401 = substr('20070401', 0, 4); $m20070401 = substr('20070401', -4, 2); $d20070401 = substr('20070401', 6); $p20070401 = $m20070401.'.'.$d20070401.'.'.$y20070401; </bloggerarchives> Quote Link to comment https://forums.phpfreaks.com/topic/42739-solved-basic-substr-problem/ Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 The mktime() function might be of use: // get the unix time stamp $time = mktime(0,0,0,$month, $day, $year); $dateDisplay = date('m.n.Y', $time); References: http://us2.php.net/manual/en/function.mktime.php http://us2.php.net/manual/en/function.date.php --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42739-solved-basic-substr-problem/#findComment-207387 Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 frost has a good suggestion. but if that's not an option, use str_replace() Quote Link to comment https://forums.phpfreaks.com/topic/42739-solved-basic-substr-problem/#findComment-207396 Share on other sites More sharing options...
bwochinski Posted March 14, 2007 Share Posted March 14, 2007 <?php $datestr = date("n.j.Y",strtotime('20070401')); ?> $datestr = "4.1.2007"; Quote Link to comment https://forums.phpfreaks.com/topic/42739-solved-basic-substr-problem/#findComment-207401 Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 <?php $datestr = date("n.j.Y",strtotime('20070401')); ?> $datestr = "4.1.2007"; why didn't i think of that!? Quote Link to comment https://forums.phpfreaks.com/topic/42739-solved-basic-substr-problem/#findComment-207402 Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 Yea, I like bwochinkski's way better. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42739-solved-basic-substr-problem/#findComment-207403 Share on other sites More sharing options...
robindean Posted March 14, 2007 Author Share Posted March 14, 2007 Many thanks! More newbie questions soon : ) Quote Link to comment https://forums.phpfreaks.com/topic/42739-solved-basic-substr-problem/#findComment-207479 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.