If you want to create one negative DateInterval, you may use the following ways
Get dateTime object two months ago.
$dateTime = (new DateTime());
var_dump($dateTime);
$month = -2;
$dateInterval = new DateInterval('P' . abs($month) . 'M');
if ($month < 0) {
$dateInterval->invert = 1;
}
$dateTime->add($dateInterval);
it will shows:
object(DateTime)[94]
public 'date' => string '2013-11-26 11:10:23' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Asia/Tokyo' (length=10)
object(DateTime)[94]
public 'date' => string '2013-09-26 11:10:23' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Asia/Tokyo' (length=10)
11/26/2013
11/21/2013
count the appearance times of string in file
When you want to count the appearance lines of one special string in a file, you may use
grep -o will-fined-string /path/to/file | wc -l
grep -o will-fined-string /path/to/file | wc -l
PHP goto keywords
goto has a bad reputation among programmers.
But sometime it is also very useful.
Here are one example
for($i=0,$j=50; $i<100 br="" i=""> while($j--) {
if($j==17) goto end;
}
}
echo "i = $i";
end:
echo 'j hit 17';100>
Paper
But sometime it is also very useful.
Here are one example
for($i=0,$j=50; $i<100 br="" i=""> while($j--) {
if($j==17) goto end;
}
}
echo "i = $i";
end:
echo 'j hit 17';100>
Paper
Subscribe to:
Posts (Atom)