<?php
include_once("AllowOrigin.php");
date_default_timezone_set("Asia/Bangkok");
header('Content-Type: application/json');
include_once("libs.php");

// function get_data($url){
//     $curl = curl_init();
//     curl_setopt_array($curl, array(
//     CURLOPT_URL => $url,
//     CURLOPT_RETURNTRANSFER => true,
//     CURLOPT_ENCODING => "",
//     CURLOPT_MAXREDIRS => 10,
//     CURLOPT_TIMEOUT => 30,
//     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//     CURLOPT_CUSTOMREQUEST => "GET",
//     CURLOPT_HTTPHEADER => array(
//         "cache-control: no-cache",
//         "postman-token: 4783b53f-adb2-4fb8-11fc-687d07cb5518"
//     ),
//     ));
//     $response = curl_exec($curl);
//     $err = curl_error($curl);
//     curl_close($curl);
//     return $response;
// }


// function Get_Value()
// {
//     $url = 'http://asia-northeast1-mybot-326003.cloudfunctions.net/nikkei';
//     $variable = get_data($url);
//     $obj = json_decode($variable);

//     $result = [];
//     $stock_name = 'นิเคอิ บ่าย';
//     $stock_date = '13:00';
// 	$flag = '🇯🇵';
//     $_unit3 = "";
//     $_unit2 = "";
//     foreach ($obj->price as $value) {
//         if ($value[0] === "15:00:00") {

//             $_filter_3 = number_format((float)$value[1], 2, '.', '');
//             $_filter_2 = number_format((float)$obj->prev[1][1], 2, '.', '');

//             $_filter_cal = $_filter_3-$_filter_2;
//             $_filter_cal = explode(".",$_filter_cal);
//             $_unit2 = $_filter_cal[1];

//             $_filter_3 = explode(".",$_filter_3);
//             $_unit3 = substr($_filter_3[0],strlen($_filter_3[0])-1).$_filter_3[1];

//             $result = [
//                 "lottery_loop_name" => $flag.$stock_name.$flag,
//                 "lottery_loop_time" => $stock_date,
//                 "lottery_loop_3unit" => $_unit3,
//                 "lottery_loop_2unit" => $_unit2,
//             ];

//         }
//     }
//     if (empty($result)) {
//         $result = [
//             "lottery_loop_name" => $flag.$stock_name.$flag,
//             "lottery_loop_time" => $stock_date,
//             "lottery_loop_3unit" => 'xxx',
//             "lottery_loop_2unit" => 'xx',
//         ];
//     }
// 	$json = [];
// 	array_push($json, $result);
//     return ['stock' => $json];
// }

// $res = Get_Value();
// echo json_encode($res);



// date_default_timezone_set("Asia/Bangkok");
// function get_dataa($url)
// {
//     $ch = curl_init();
//     curl_setopt($ch, CURLOPT_URL, $url);
//     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36");
//     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//     curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
//     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//     curl_setopt($ch, CURLOPT_POST, true);
//     curl_setopt($ch, CURLOPT_POSTFIELDS, rawurldecode(http_build_query(array('DateNow' => date("Y-m-d H:i:s")))));
//     $data = curl_exec($ch);
//     curl_close($ch);
//     return $data;
// }

// function remove_empty($array) {
//     return array_filter($array, '_remove_empty_internal');
// }

// function _remove_empty_internal($value) {
//     return !empty($value) || $value === 0;
// }

// function FilterData(){
// 	// $variableee         = get_dataa('https://xn--l3c1aonc.net/%E0%B8%AB%E0%B8%A7%E0%B8%A2%E0%B8%AB%E0%B8%B8%E0%B9%89%E0%B8%99/'); // https://หวยสด.net/หวยหุ้น/
// 	// $start              = strpos($variableee,"<span>นิเคอิ (บ่าย)</span>");
// 	// $start_cut          = substr($variableee,$start);
// 	// $stop               = strpos($start_cut,"<div  class='lotto-row  row m-0 p-0'>");
// 	// $sub                = strip_tags(substr($start_cut,0,$stop));

//     $variableee         = get_dataa('https://www.huaysod.com/'); // https://หวยสด.net/หวยหุ้น/
// 	$start              = strpos($variableee,"นิเคอิปิดบ่าย");
// 	$start_cut          = substr($variableee,$start);
// 	$stop               = strpos($start_cut,"co03m co03mx");
// 	$sub                = strip_tags(substr($start_cut,0,$stop));

//     $stock_name = 'นิเคอิ บ่าย';
//     $stock_date = '13:00';
// 	$flag = '🇯🇵';
// 	$jsonloop = [];

// 	$FilterHTML 		= strip_tags(trim($sub));
// 	$data       		= explode("\n",$FilterHTML);
// 	$trimmedArray 		= array_map('trim', $data);
// 	$filterData 		= [];
// 	foreach ($trimmedArray as $key => $value) {
// 		if(trim($value) != ''){
// 			array_push($filterData,$value);
// 		}
// 	}

// 	if(trim($filterData[2]) == 'รอผล'){$filterData[1] = 'xxx';}
// 	if(trim($filterData[4]) == 'รอผล'){$filterData[3] = 'xx';}
// 	array_push($jsonloop,[
// 		"lottery_loop_name"       => $flag.$stock_name.$flag,
// 		"lottery_loop_time"       => $stock_date,
// 		"lottery_loop_3unit"      => trim($filterData[2]),
// 		"lottery_loop_2unit"      => trim($filterData[4])
// 	]);
//     return ['stock'    => $jsonloop];
// }

// $res = FilterData();
// echo json_encode($res);


// include_once("libs.php");

## เปลี่ยนค่าตามผลที่ใช้ ##
define("_name_","ผลหวย นิคเคอิบ่าย");
define("_url_","https://stock-nikkei.atmybot.workers.dev/");
define("_stock_name_","นิคเคอิบ่าย");
define("_stock_date_","13:00");
define("_flag_",'🇯🇵');
## เปลี่ยนค่าตามผลที่ใช้ ##

//---------------- SN 06.11.2024 PP ------------------
function Get_Value()
{
    // $url 		= 'https://indexes.nikkei.co.jp/en/nkave/get_real_data?idx=nk225';
    $response 	= get_data(_url_);  //N 06/11/2025 PP
    // echo '<pre>';
    // print_r($response);
    $obj = json_decode($response);
    // print_r($obj);
    $result = [];
    $unit3 = 'xxx';
    $unit2 = 'xx';



    // เช็คว่ามีคำว่า "(*Close)" อยู่ใน [datedtime] หรือไม่
    if (strpos($obj->datedtime, "(Close)") !== false) {
        //echo "[datedtime] contains '(*Close)'.";

        // ลบส่วนที่ไม่ต้องการออก
        $cleanDate = preg_replace('/\(\Close\)/', '', $obj->datedtime);
        $cleanDate = trim($cleanDate); // ลบช่องว่างข้างหน้าและข้างหลัง
    	// print_r($cleanDate);

        // สร้างวัตถุ DateTime จากวันที่ที่จัดรูปแบบแล้ว
        $dateFromData = DateTime::createFromFormat('M/d/Y', $cleanDate);

        // สร้างวัตถุ DateTime ของวันที่ปัจจุบัน
        $currentDate = new DateTime();

        // เปรียบเทียบวันที่
        if ($dateFromData && $dateFromData->format('Y-m-d') === $currentDate->format('Y-m-d')) {
            //echo "วันที่ตรงกัน";

            // change code unit3 27-05-2567 AP
            // $unit3_edit = number_format("39,381.41", 2, '.', ',');
            // $unit2_edit = number_format($obj->diff, 2, '.', ',');
            // $unit3_real = str_replace([",", "."], "", $unit3_edit);
            // $unit2_real = str_replace([",", "."], "", $unit2_edit);
            // change code unit3 27-05-2567 AP

            $unit3 = $obj->price;
            $unit2 = $obj->diff;

            // echo $unit2;
            // print_r($obj);

            $result = [
                "lottery_loop_name" => _flag_ . _stock_name_ . _flag_,
                "lottery_loop_time" => _stock_date_,

                // //--------------------------------------
                // "lottery_loop_3unit" => substr($unit3_real, -3), // change code unit3 27-05-2567 AP
                // "lottery_loop_2unit" => substr($unit2_real, -2), // change code unit3 27-05-2567 AP

                // //------------- show all stock ---------
                // "price" => $unit3_edit, // change code unit3 27-05-2567 AP
                // "change" => $unit2_edit  // change code unit3 27-05-2567 AP

                "lottery_loop_3unit" =>getThreeDigits($unit3),
                "lottery_loop_2unit" =>getTwoDigits($unit2),
                "price" => $unit3,
                "change" => $unit2
            ];
        } else {
            $result = [
                "lottery_loop_name" => _flag_ . _stock_name_ . _flag_,
                "lottery_loop_time" => _stock_date_,

                //--------------------------------------
                "lottery_loop_3unit" => 'xxx', // change code unit3 27-05-2567 AP
                "lottery_loop_2unit" => 'xx', // change code unit3 27-05-2567 AP

                //------------- show all stock ---------
                "price" => 'xxx', // change code unit3 27-05-2567 AP
                "change" => 'xx'  //  change code unit3 27-05-2567 AP
            ];
        }
    } else {
        $result = [
   			"lottery_loop_name" => _flag_ . _stock_name_ . _flag_,
            "lottery_loop_time" => _stock_date_,

            //--------------------------------------
            "lottery_loop_3unit" => 'xxx', // change code unit3 27-05-2567 AP
            "lottery_loop_2unit" => 'xx', // change code unit3 27-05-2567 AP

            //------------- show all stock ---------
            "price" => 'xxx', // change code unit3 27-05-2567 AP
            "change" => 'xx'  //  change code unit3 27-05-2567 AP
        ];
    }

    // foreach ($obj as $value) {
    //     if ($value->category === "หวยหุ้น") {
    //        foreach ($value->data as $value_data) {
    //         	if($value_data->name === 'หวยหุ้นนิเคอิ (บ่าย)'){
    //             	if($value_data->huayResultModel->result != null ){
    //           			$_unit3 = $value_data->huayResultModel->result->primaryNumber;
    //                 	$_unit2 = $value_data->huayResultModel->result->twoNumber;
    //                 }
    //                 $result = [
    //             		"lottery_loop_name" => $flag.$stock_name.$flag,
    //             		"lottery_loop_time" => $stock_date,
    //             		"lottery_loop_3unit" => $_unit3,
    //             		"lottery_loop_2unit" => $_unit2,
    //         		];   
    //         	}   
    //        }
    //     }

    // }
    // $json = [];
    // array_push($json, $result);
    // return ['stock' => $json];
    $json = [];
    array_push($json, $result);
    return ['stock' => $json];
}

$res = Get_Value();
echo json_encode($res);



// function get_data($url){
//     $curl = curl_init();
//     curl_setopt_array($curl, array(
//     CURLOPT_URL => $url,
//     CURLOPT_RETURNTRANSFER => true,
//     CURLOPT_ENCODING => "",
//     CURLOPT_MAXREDIRS => 10,
//     CURLOPT_TIMEOUT => 30,
//     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//     CURLOPT_CUSTOMREQUEST => "GET",
//     CURLOPT_HTTPHEADER => array(
//         "cache-control: no-cache",
//         "postman-token: 51464584-baf6-985d-c539-96c559e6ad4d"
//     ),
//     ));
//     $response = curl_exec($curl);
//     $err = curl_error($curl);
//     curl_close($curl);
//     return $response;
// }


// function Get_Value(){
//     $url = 'https://center.huayded888.com/api/v1/results';
//     $variable = get_data($url);
//     $obj = json_decode($variable);
//     $result = [];
//     $stock_name = 'นิคเคอิบ่าย';
//     $stock_date = '13:00';
// 	$flag = '🇯🇵';
//     $_unit3 = "xxx";
//     $_unit2 = "xx";

//     foreach ($obj as $value) {
//         if ($value->category === "หวยหุ้น") {
//            foreach ($value->data as $value_data) {
//             	if($value_data->name === 'หวยหุ้นนิเคอิ (บ่าย)'){
//                 	if($value_data->huayResultModel->result != null ){
//               			$_unit3 = $value_data->huayResultModel->result->primaryNumber;
//                     	$_unit2 = $value_data->huayResultModel->result->twoNumber;
//                     }
//                     $result = [
//                 		"lottery_loop_name" => $flag.$stock_name.$flag,
//                 		"lottery_loop_time" => $stock_date,
//                 		"lottery_loop_3unit" => $_unit3,
//                 		"lottery_loop_2unit" => $_unit2,
//             		];   
//             	}   
//            }
//         }

//     }
// 	$json = [];
// 	array_push($json, $result);
// 	return ['stock' => $json];
// }

// $res = Get_Value();
// echo json_encode($res);




// function get_data($url){
//     $curl = curl_init();
//     curl_setopt_array($curl, array(
//     CURLOPT_URL => $url,
//     CURLOPT_RETURNTRANSFER => true,
//     CURLOPT_ENCODING => "",
//     CURLOPT_MAXREDIRS => 10,
//     CURLOPT_TIMEOUT => 30,
//     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//     CURLOPT_CUSTOMREQUEST => "GET",
//     CURLOPT_HTTPHEADER => array(
//         "cache-control: no-cache",
//         "postman-token: 51464584-baf6-985d-c539-96c559e6ad4d"
//     ),
//     ));
//     $response = curl_exec($curl);
//     $err = curl_error($curl);
//     curl_close($curl);
//     return $response;
// }

// function Get_Value(){
//     $url = 'https://api.kerry888.com/api/home';
//     $variable = get_data($url);
//     $obj = json_decode($variable);
//     $result = [];
//     $stock_name = 'นิคเคอิบ่าย';
//     $stock_date = '13:00';
// 	$flag = '🇯🇵';
//     $_unit3 = "xxx";
//     $_unit2 = "xx";

//     foreach ($obj->settrandNoInt->lists as $value) {
//     	if (trim($value->GAME_NAME) === "นิเคอิปิดบ่าย") {
//         	if($value->RESULT_3UP !== "รอผล" && $value->RESULT_2DOWN !== "รอผล"){
//             	$_unit3 = $value->RESULT_3UP;
//             	$_unit2 = $value->RESULT_2DOWN;
//        		}
//         	// $result = [
//         	// "lottery_loop_name" => $flag.$stock_name.$flag,
//         	// "lottery_loop_time" => $stock_date,
//         	// "lottery_loop_3unit" => $_unit3,
//         	// "lottery_loop_2unit" => $_unit2,
//         	// ]; 
//         }
//     }

// 	// SN 24/12/2023 PP
// 	$_day_of_week = intval(date("N"));
// 	if($_day_of_week === 6 or $_day_of_week === 7) {
//     	$result = [
//            	"lottery_loop_name" => $flag.$stock_name.$flag,
//            	"lottery_loop_time" => $stock_date,
//            	"lottery_loop_3unit" => "xxx",
//            	"lottery_loop_2unit" => "xx",
//         ]; 
//     } else {
//     	$result = [
//            	"lottery_loop_name" => $flag.$stock_name.$flag,
//            	"lottery_loop_time" => $stock_date,
//            	"lottery_loop_3unit" => $_unit3,
//            	"lottery_loop_2unit" => $_unit2,
//         ]; 
//     }
// 	// EN 24/12/2023 PP


// 	$json = [];
// 	array_push($json, $result);
// 	return ['stock' => $json];
// }
// $res = Get_Value();
// echo json_encode($res);



// include "libs.php";

// function _get_(){
//     $url                = 'https://lottoexp.com/result';
//     $result             = [];

// 	$stock_name         = 'ฮานอยเช้า';
// 	$stock_date         = '13:00';
// 	$flag               = '🇯🇵';
//     $_unit3             = "xxx";
//     $_unit2             = "xx";

//     $variableee         = get_data($url); 
//     $start              = strpos($variableee, $stock_name.'</a></td>');
//     $start_cut          = substr($variableee, $start);
//     $stop               = strpos($start_cut, '</tr>');
//     $sub                = substr($start_cut, 0, $stop);
//     $mackup             = '<table><td><a>'.$sub.'</table>';
//     $xml                = @simplexml_load_string($mackup);

//     $_unit3             = @((array) $xml->td[1][0])[0];
//     $_unit2             = @((array) $xml->td[2][0])[0];

//     $result = [
//         "lottery_loop_name"     => $flag.$stock_name.$flag,
//         "lottery_loop_time"     => $stock_date,
//         "lottery_loop_3unit"    => $_unit3 != null ? $_unit3 : 'xxx',
//         "lottery_loop_2unit"    => $_unit2 != null ? $_unit2 : 'xx'
//     ]; 

// 	$json               = [];
// 	array_push($json, $result);
// 	return ['stock'     => $json];
// }
// $res = _get_();
// echo json_encode($res);


// include "libs.php";

// function _get_()
// {
//     $url = 'https://lottoexp.com/_next/data/_nIKjD1Bo3uuwMkiI81Wu/nikkei-afternoon.json?lottos=nikkei-afternoon';
//     $result = [];
//     $stock_name     = 'นิคเคอิบ่าย';
//     $stock_date     = '13:00';
//     $flag           = '🇯🇵';
//     $_unit3         = "xxx";
//     $_unit2         = "xx";
//     // $ToDay          = date('Y-d-m');
// 	$ToDay          = date('Y-m-d'); // AP
//     $result         = getResultAPIs($url);
//     $data           = $result->pageProps->data;
//     $StockDay       = explode('T',$data[0]->lottosDate);
//     // if ($StockDay == $ToDay) {
// 	if ($StockDay[0] == $ToDay) { // AP
//         $_unit3 = $data[0]->lottosNumber;
//         $_unit2 = $data[0]->lottosUnder;
//     }
//     $result = [
//         "lottery_loop_name" => $flag . $stock_name . $flag,
//         "lottery_loop_time" => $stock_date,
//         "lottery_loop_3unit" => $_unit3 != null ? $_unit3 : 'xxx',
//         "lottery_loop_2unit" => $_unit2 != null ? $_unit2 : 'xx'
//     ];
//     $json = [];
//     array_push($json, $result);
//     return ['stock' => $json];
// }
// $res = _get_();

// include "libs.php";

// $config = array(
//     'Stock_url'         => 'https://lottoexp.com/_next/data/_nIKjD1Bo3uuwMkiI81Wu/nikkei-afternoon.json?lottos=nikkei-afternoon',
//     'Stock_name'        => 'นิคเคอิบ่าย',
//     'Stock_date'        => '13:00',
//     'Stock_flag'        => '🇯🇵',
//     'Stock_id'          => 9,
// );
// $res = _get_Web_lottoexp_api($config);
// echo json_encode($res);

// include "libs.php";

// function get_api($url){
// 	$curl = curl_init();
// 	curl_setopt_array($curl, array(
//   		CURLOPT_URL => $url,
//   		CURLOPT_RETURNTRANSFER => true,
//   		CURLOPT_ENCODING => '',
//   		CURLOPT_MAXREDIRS => 10,
//   		CURLOPT_TIMEOUT => 0,
//   		CURLOPT_FOLLOWLOCATION => true,
//   		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//   		CURLOPT_CUSTOMREQUEST => 'GET',
//       	CURLOPT_HTTPHEADER => array(
//     		'Cookie: _gid=GA1.3.970257431.1762317493; __utmc=168498041; __utmz=168498041.1762400028.3.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); __utma=168498041.931350917.1762317493.1762400028.1762415377.4; __utmb=168498041.2.10.1762415377; _ga_VNKGMELPRS=GS2.1.s1762415377$o3$g1$t1762415381$j56$l0$h0; _ga=GA1.1.1945016921.1762317493'
//   		),
// 	));
// 	$response = curl_exec($curl);
// 	curl_close($curl);
// 	// echo $response;
//     return $response;
// }


// //---------------- SN 06.11.2024 PP ------------------
// function Get_Value()
// {
//     $url 		= 'https://indexes.nikkei.co.jp/en/nkave/get_real_data?idx=nk225';
//     $response 	= get_api($url);  //N 06/11/2025 PP
//     echo '<pre>';
//     print_r($response);
//     // $obj = json_decode($variable);
//     // print_r($obj);
//     $result = [];
//     $stock_name = 'นิคเคอิบ่าย';
//     $stock_date = '13:00';
//     $flag = '🇯🇵';
//     $unit3 = 'xxx';
//     $unit2 = 'xx';



//     // เช็คว่ามีคำว่า "(*Close)" อยู่ใน [datedtime] หรือไม่
//     if (strpos($obj->datedtime, "(*Close)") !== false) {
//         //echo "[datedtime] contains '(*Close)'.";

//         // ลบส่วนที่ไม่ต้องการออก
//         $cleanDate = preg_replace('/\(\*Close\)/', '', $obj->datedtime);
//         $cleanDate = trim($cleanDate); // ลบช่องว่างข้างหน้าและข้างหลัง

//         // สร้างวัตถุ DateTime จากวันที่ที่จัดรูปแบบแล้ว
//         $dateFromData = DateTime::createFromFormat('M/d/Y', $cleanDate);

//         // สร้างวัตถุ DateTime ของวันที่ปัจจุบัน
//         $currentDate = new DateTime();

//         // เปรียบเทียบวันที่
//         if ($dateFromData && $dateFromData->format('Y-m-d') === $currentDate->format('Y-m-d')) {
//             //echo "วันที่ตรงกัน";

//             // change code unit3 27-05-2567 AP
//             // $unit3_edit = number_format("39,381.41", 2, '.', ',');
//             // $unit2_edit = number_format($obj->diff, 2, '.', ',');
//             // $unit3_real = str_replace([",", "."], "", $unit3_edit);
//             // $unit2_real = str_replace([",", "."], "", $unit2_edit);
//             // change code unit3 27-05-2567 AP

//             $unit3 = $obj->price;
//             $unit2 = $obj->diff;

//             // echo $unit2;
//             // print_r($obj);

//             $result = [
//                 "lottery_loop_name" => $flag . $stock_name . $flag,
//                 "lottery_loop_time" => $stock_date,

//                 // //--------------------------------------
//                 // "lottery_loop_3unit" => substr($unit3_real, -3), // change code unit3 27-05-2567 AP
//                 // "lottery_loop_2unit" => substr($unit2_real, -2), // change code unit3 27-05-2567 AP

//                 // //------------- show all stock ---------
//                 // "price" => $unit3_edit, // change code unit3 27-05-2567 AP
//                 // "change" => $unit2_edit  // change code unit3 27-05-2567 AP

//                 "lottery_loop_3unit" =>getThreeDigits($unit3),
//                 "lottery_loop_2unit" =>getTwoDigits($unit2),
//                 "price" => $unit3,
//                 "change" => $unit2
//             ];
//         } else {
//             $result = [
//                 "lottery_loop_name" => $flag . $stock_name . $flag,
//                 "lottery_loop_time" => $stock_date,

//                 //--------------------------------------
//                 "lottery_loop_3unit" => 'xxx', // change code unit3 27-05-2567 AP
//                 "lottery_loop_2unit" => 'xx', // change code unit3 27-05-2567 AP

//                 //------------- show all stock ---------
//                 "price" => 'xxx', // change code unit3 27-05-2567 AP
//                 "change" => 'xx'  //  change code unit3 27-05-2567 AP
//             ];
//         }
//     } else {
//         $result = [
//             "lottery_loop_name" => $flag . $stock_name . $flag,
//             "lottery_loop_time" => $stock_date,

//             //--------------------------------------
//             "lottery_loop_3unit" => 'xxx', // change code unit3 27-05-2567 AP
//             "lottery_loop_2unit" => 'xx', // change code unit3 27-05-2567 AP

//             //------------- show all stock ---------
//             "price" => 'xxx', // change code unit3 27-05-2567 AP
//             "change" => 'xx'  //  change code unit3 27-05-2567 AP
//         ];
//     }

//     // // foreach ($obj as $value) {
//     // //     if ($value->category === "หวยหุ้น") {
//     // //        foreach ($value->data as $value_data) {
//     // //         	if($value_data->name === 'หวยหุ้นนิเคอิ (บ่าย)'){
//     // //             	if($value_data->huayResultModel->result != null ){
//     // //           			$_unit3 = $value_data->huayResultModel->result->primaryNumber;
//     // //                 	$_unit2 = $value_data->huayResultModel->result->twoNumber;
//     // //                 }
//     // //                 $result = [
//     // //             		"lottery_loop_name" => $flag.$stock_name.$flag,
//     // //             		"lottery_loop_time" => $stock_date,
//     // //             		"lottery_loop_3unit" => $_unit3,
//     // //             		"lottery_loop_2unit" => $_unit2,
//     // //         		];   
//     // //         	}   
//     // //        }
//     // //     }

//     // // }
//     // // $json = [];
//     // // array_push($json, $result);
//     // // return ['stock' => $json];
//     $json = [];
//     array_push($json, $result);
//     return ['stock' => $json];
// }

// $res = Get_Value();
// echo json_encode($res);


// //---------------- EN 06.11.2024 PP ------------------


// // $file_path = 'nikkei_pm.json';
// // $json_data = file_get_contents($file_path);
// // echo $json_data;

//----------------------------------------- SN 08/11/2025 PP -------------------------------------

// ## เปลี่ยนค่าตามผลที่ใช้ ##
// define("_name_","ผลหวย นิคเคอิบ่าย");
// define("_url_","https://stock-nikkei.atmybot.workers.dev");
// define("_stock_name_","นิเคอิบ่าย");
// define("_stock_date_","13:00");
// define("_flag_",'🇯🇵');
// ## เปลี่ยนค่าตามผลที่ใช้ ##

// function get_webpageApi($url)
// {
// 	// // ใส่ RapidAPI key ของคุณที่นี่
// 	$apiKey = '7305809129msh6b79654284df728p1ef323jsn84fb1947c34c';
// 	$query = http_build_query([
//     	'symbol'   => '^N225',   // หรือ '%5EN225'
//     	'interval' => '1d',
//     	'range'    => '1d'       // เปลี่ยน range ตามต้องการ (1d,5d,1mo,1y ฯลฯ)
// 	]);

// 	$ch = curl_init("{$url}?{$query}");
// 	curl_setopt_array($ch, [
//     	CURLOPT_RETURNTRANSFER => true,
//     	CURLOPT_FOLLOWLOCATION => true,
//     	CURLOPT_TIMEOUT => 20,
//     	CURLOPT_HTTPHEADER => [
//         	"x-rapidapi-host: apidojo-yahoo-finance-v1.p.rapidapi.com",
//        	 	"x-rapidapi-key: {$apiKey}",
//         	"Accept: application/json"
//     	],
// 	]);

// 	$response = curl_exec($ch);
// 	$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// 	$err = curl_error($ch);
// 	curl_close($ch);

// 	if ($response === false) {
//    	 	echo "CURL Error: {$err}\n";
//    	 	exit;
// 	}

// 	if ($httpCode !== 200) {
//     	echo "HTTP {$httpCode}\n";
//     	echo $response;
//     	exit;
// 	}

// 	// แปลง JSON เป็น array
// 	$data = json_decode($response, true);
// 	header('Content-Type: application/json; charset=utf-8');
//     return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
// }
// function Get_Value()
// {
//     $res            		= json_decode(get_data(_url_));
	
// //$result					= $res->chart->result[0];
// 	$api_dt					= date("Y-m-d",$result->timestamp[0]);
// 	// $server_dt			= date("Y-m-d");
// 	$server_dt				= "2025-11-07";
// 	$regularMarketPrice 	= $result->meta->regularMarketPrice;
// 	$chartPreviousClose 	= $result->meta->chartPreviousClose;
// 	$change					= $chartPreviousClose - $regularMarketPrice;
//     $unit_3         		= 'xxx';
//     $unit_2         		= 'xx';
//     $jsonloop       		= [];
//     if ($server_dt == $api_dt) {
//         # code...
// 		$unit_3				= getThreeDigits($regularMarketPrice);
// 		$unit_2				= getTwoDigits($change);
//     }
//     array_push($jsonloop, [
//         "lottery_loop_name"         => _flag_ . _stock_name_ . _flag_,
//         "lottery_loop_time"         => _stock_date_,
//         "lottery_loop_3unit"        => $unit_3,
//         "lottery_loop_2unit"        => $unit_2,
//     ]);
//     return ['stock' => $jsonloop];
// }
// $res = Get_Value();
// echo json_encode($res);

// //----------------------------------------- EN 08/11/2025 PP -------------------------------------