English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP 기본 강의

PHP 고급 강의

PHP & MySQL

PHP 참조 설명서

PHP date_get_last_errors() 함수 사용법 및 예제

PHP Date & Time 함수 매뉴얼

date_get_last_errors() 함수는 경고와 오류 정보를 얻습니다

정의와 사용법

date_get_last_errors()는 DateTime::getLastErrors()::__construct()의 별명입니다. 이 함수는 날짜 문자열을 분석할 때 발생하는 경고와 오류를 얻기 위해 사용됩니다.

문법

date_get_last_errors();

파라미터

이 함수는 어떤 파라미터도 받지 않습니다

반환 값

PHP date_get_last_errors() 함수는 날짜 문자열을 해석하려고 시도할 때 발생한 모든 경고와 오류를 포함한 배열을 반환합니다.

PHP 버전

이 함수는 초기로 PHP 버전5.5.0에서 도입되었으며 모든 높은 버전에서 사용할 수 있습니다.

온라인 예제

다음 예제에서는 다음과 같이 표시됩니다date_get_last_errors()함수 사용법-

<?php
   date_create("215-7896-848");
   $errors = date_get_last_errors();
   print_r($errors);
?>
테스트 봐‹/›

출력 결과

Array
(
    [warning_count] => 1
    [warnings] => Array
        (
            [8] => Double timezone specification
        )
    [error_count] => 5
    [errors] => Array
        (
            [0] => Unexpected character
            [1] => Unexpected character
            [2] => Unexpected character
            [6] => Unexpected character
            [7] => Unexpected character
        )
)

온라인 예제

이 함수를 사용하면 날짜 생성 시 발생한 오류를 캡처할 수 있습니다.-

<?php
   try { 
      $res = new DateTime("215-7896-848");
      print($res);
   }  catch (Exception $e) { 
      print_r(DateTime::getLastErrors()); 
   }  
?>
테스트 봐‹/›

출력 결과

Array
(
    [warning_count] => 1
    [warnings] => Array
        (
            [8] => Double timezone specification
        )
    [error_count] => 5
    [errors] => Array
        (
            [0] => Unexpected character
            [1] => Unexpected character
            [2] => Unexpected character
            [6] => Unexpected character
            [7] => Unexpected character
        )
)

온라인 예제

다음 예제에서는 다음과 같이 사용date_create_from_format()DateTime 객체를 생성할 때 발생한 오류/경고-

//DateTime 객체를 생성하십시오
$date = "25-Mar-1989";
$format = "d-Z-Y";
$res = date_create_from_format($format, $date);
print_r(date_get_last_errors());
테스트 봐‹/›

출력 결과

Array
(
    [warning_count] => 0
    [warnings] => Array
        (
        )
    [error_count] => 3
    [errors] => Array
        (
            [3] => The format separator does not match
            [4] => Unexpected data found.
        )
)