<pre><?php

        $url = 'https://www.canada411.ca/search/si/' . rand(1, 10) . '/khan/Toronto/';

        // Initialize cURL
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)');
        $html = curl_exec($ch);
        curl_close($ch);

        // Load HTML into DOMDocument
        $doc = new DOMDocument();
        libxml_use_internal_errors(true); // Suppress warnings due to malformed HTML
        $doc->loadHTML($html);
        libxml_clear_errors();

        $xpath = new DOMXPath($doc);

        // Find the parent container
        $parentDiv = $xpath->query("//div[contains(@class, 'c411ResultList')]")->item(0);

        if ($parentDiv) {
            // Iterate over direct children of the parent div
            foreach ($parentDiv->childNodes as $entry) {
                if ($entry->nodeType !== XML_ELEMENT_NODE) continue;

                // Extract name
                $nameNode = $xpath->query(".//h2[contains(@class, 'c411ListedName')]", $entry)->item(0);
                $name = $nameNode ? trim($nameNode->nodeValue) : 'N/A';
                $name = strip_tags($name); // Remove any HTML tags

                // Extract phone
                $phoneNode = $xpath->query(".//span[contains(@class, 'c411Phone')]", $entry)->item(0);
                $phone = $phoneNode ? trim($phoneNode->nodeValue) : 'N/A';

                // Extract address
                $addressNode = $xpath->query(".//span[contains(@class, 'adr')]", $entry)->item(0);
                $address = $addressNode ? trim($addressNode->nodeValue) : 'N/A';

                // Output the result
                echo "Name: $name\n";
                echo "Phone: $phone\n";
                echo "Address: $address\n";
                echo "-------------------------\n";
            }
        } else {
            echo "No results found or container missing.";
        }
