Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Feb 26, 2014

Hàm Kiểm tra ngày tháng có đúng không trong php.

function isValidDateTimeString($str_dt, $str_dateformat, $str_timezone) {
  $date = DateTime::createFromFormat($str_dateformat, $str_dt, new DateTimeZone($str_timezone));
  return $date && DateTime::getLastErrors()["warning_count"] == 0 && DateTime::getLastErrors()["error_count"] == 0;
}

Sep 24, 2013

PHP isset() vs empty() vs is_null()

PHP has different functions which can be used to test the value of a variable. Three useful functions for this are isset(), empty() and is_null(). All these function return a boolean value. If these functions are not used in correct way they can cause unexpected results.
isset() and empty() are often viewed as functions that are opposite, however this is not always true. In this post I will explain the differences between these functions.

Jun 14, 2013

Kiểu DateTime trong PHP

Một số thủ thuật để xử lý DateTime trong PHP: lấy ngày tháng hiện tại, so sánh ngày, tính thời gian chênh lệch giữa 2 ngày.