How to access a html element in a PHP async function

I am writing a php where one of its function is to scrape data from internet. Thanks to Barmar, now I can display my scrapping result smoothly in my index.php file. Now, I want to update my scraping result to my database. But before that, I need to access to my scrapping result inside the tag of id “result”. Here is my php:

<!DOCTYPE html>
<html>     
<head>
<meta charset="utf-8" />
<title>contacts.php</title>
</head>
<body>

    <div id="result">
    </div>

<?php
    $tz = 'Asia/Hong_Kong';
    $timestamp = time();
    $dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
    $dt->setTimestamp($timestamp); //adjust the object to correct timestamp

    $eng_gov_html = 'https://www.info.gov.hk/gia/wr/' . substr($dt->format('Y/m/d'),0, 4) . substr($dt->format('Y/m/d'),5, 2) . '/'. substr($dt->format('Y/m/d'),8, 2) . '.htm';

    $rootFolder = dirname(__DIR__);
    require_once $rootFolder.'/Bulletin Translator/private/lib/vendor/autoload.php';

    $client = new GuzzleHttpClient();
    $response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');

    // Send an asynchronous request.
    $request = new GuzzleHttpPsr7Request('GET', $chin_gov_html);
    $promise = $client->sendAsync($request)->then(function ($response) 
    {
        $doc = new DOMDocument();

        $body = (string) $response->getBody();
        libxml_use_internal_errors(true);
        $doc->loadHTML($body);
        $xpath = new DOMXPath($doc);
    

        $bulltin_name = $xpath->evaluate('//body/div/div/div/ul/li/a');
        echo '<script>document.getElementById("result").innerHTML = "";</script>';

        foreach($bulltin_name as $element)
        {
            //print_r($element->textContent."<br>");
            echo '<script>

                    for (i = 0; i <'. json_encode($element->textContent, JSON_UNESCAPED_UNICODE) .'.length; i++)
                    {
                        if ('. json_encode($element->textContent, JSON_UNESCAPED_UNICODE) .'.substring(i, i+1)!=" ")
                        {
                            document.getElementById("result").innerHTML+='. json_encode($element->textContent, JSON_UNESCAPED_UNICODE) .'.substring(i, i+1);
                        }
                    }
                    document.getElementById("result").innerHTML+="</br>";

                </script>';
        }

    
        echo '<script>
                    var total_bulletin_number = document.getElementById("result").innerHTML.split("天氣稿第").length - 1;
              </script>';

       $bulltin_url = $xpath->evaluate('//body/div/div/div/ul/li/a/@href');
       foreach($bulltin_url as $url)
       {
            echo '<script> document.getElementById("result").innerHTML+='. json_encode($url->textContent,JSON_UNESCAPED_UNICODE) .'+ "</br>"</script>';
        }

        echo '<script>
                  var content_array = document.getElementById("result").innerHTML.split("<br>");
                  document.getElementById("result").innerHTML = "";
              
                  for (c = total_bulletin_number - 1; c >= 0 ; c--)
                  {
                      document.getElementById("result").innerHTML += content_array[c].substring(4, 7) + ": " + content_array[c].substring(9) + ", " + "https://www.info.gov.hk" + content_array[total_bulletin_number + c] + "</br>";
                  }
              
                  document.getElementById("result").removeChild(document.getElementById("result").lastElementChild);
                  content_array = document.getElementById("result").innerHTML.split("<br>");
              </script>';
    
        $result = $doc->getElementById('result')->textContent;
        print_r(explode("htm", $result));
    });

    $promise->wait();
?>

<?php

    // Some script here to upload the result to database...
    // Some script here to upload the result to database...
    // Some script here to upload the result to database...

?>
</body>
</html>

Now, I want to perform an operation in php like this as if in javascript:

var content_array = document.getElementById("result").innerHTML.split(".htm");
var content_arrary_length = content_array.length;

I try to add two lines at the end of my php script:

$result = $doc->getElementById('result')->textContent;
print_r(explode("htm", $result));
print_r(count(explode("htm", $result));

However, an error is returned:

Warning: Attempt to read property "textContent" on null in C:xampphtdocsBulletin Translatorindex.php on line 118

What shall I do to asign a varibale to the result div within the same php file?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật