best way to strip a leading 0 from numerical representation of a month?
So I have a PHP variable w/ a (possibly the current, possibly not) month in it开发者_JS百科 in the form of ##. If the month is less then October I want to take the leading 0 out. Is there a good and simple way to do this?
Cast it as an integer:
<?php
$month = '01';
echo (int) $month; // prints 1
?>
You can use the built in date function to do this, should look something like
<?php
date('n/d/Y',strtotime($dateVariable));
?>
You can use n instead of m to display the month without the leading zeros.
See http://php.net/manual/en/function.date.php for more information about date formatting.
<?php
$month = '05'; // May
$month *= 1;
echo $month;
?>
Output
5
$today_mem = date("j.n");
Use j
instead of d
and n
instead of m:
source:: https://www.php.net/manual/en/function.date.php
you can do it like:
<?php
$month = intval(Date('m'));
echo $month; // prints int value
?>
精彩评论