PHP code example of chanthorn / carbon-kh

1. Go to this page and download the library: Download chanthorn/carbon-kh library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chanthorn / carbon-kh example snippets




use Carbon\Carbon;
use Chanthorn\CarbonKh\ToKhmerDate;

    $date = Carbon::parse('2023-01-01');
    $khmerDate = new ToKhmerDate($date);

    echo $khmerDate::format(); // ថ្ងៃអាទិត្យ ១០កើត ខែបុស្ស ឆ្នាំខាល ចត្វាស័ក ពុទ្ធសករាជ ២៥៦៦
    echo $khmerDate::format('dN ថ្ងៃW ខែm ព.ស. b'); // ១០កើត ថ្ងៃអាទិត្យ ខែបុស្ស ព.ស. ២៥៦៦

    print_r($khmerDate::khNewYear());
    // array:3 [
    //   "date" => Carbon\Carbon
    //   "days" => 3
    //   "dates" => array:3
    // ]




echo khmerDate('2024-01-01')->format();
//ថ្ងៃច័ន្ទ ៥រោច ខែមិគសិរ ឆ្នាំថោះ បញ្ចស័ក ពុទ្ធសករាជ ២៥៦៧

print_r(khmerDate('2024-01-01')::khNewYear());

print_r(KhmerNewYearDate(2024));
// array:3 [
//   "date" => Carbon\Carbon
//   "days" => 4
//   "dates" => array:4
// ]

use Chanthorn\CarbonKh\ToKhmerDate;

    $date = Carbon::parse('2023-01-01');
    $khmerDate = new ToKhmerDate($date);

    echo $khmerDate::format(); // ថ្ងៃអាទិត្យ ១០កើត ខែបុស្ស ឆ្នាំខាល ចត្វាស័ករាជ ២៥៦៦
    echo $khmerDate::format('dN ថ្ងៃW ខែm ព.ស. b'); // ១០កើត ថ្ងៃអាទិត្យ ខែបុស្ស ព.ស. ២៥៦៦

    print_r($khmerDate::khNewYear());
    // array:3 [
    //   "date" => Carbon\Carbon
    //   "days" => 3
    //   "dates" => array:3
    // ]