File manager - Edit - /home/meharhashir55/gptai55/fetch_web_data.php
Back
<?php function fetchFromWeb($query) { $searchQuery = urlencode($query); // echo "<script>console.log('PHP Encoded Query: " . $searchQuery . "');</script>"; echo "Today's date is: " . date("F j, Y"); // Use DuckDuckGo search URL instead of Google $url = "https://html.duckduckgo.com/html?q={$searchQuery}"; // Fetch content using file_get_contents $response = @file_get_contents($url); // Handle errors if ($response === false) { return "Error: Unable to fetch data."; } // Save HTML for debugging // file_put_contents("debug_duckduckgo.html", $response); // Parse results return parseDuckDuckGoResults($response); } function parseDuckDuckGoResults($html) { $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); // Try to extract search results $nodes = $xpath->query("//div[contains(@class,'results')]"); if ($nodes->length > 0) { return trim($nodes->item(0)->textContent); // Extract first search result title } return "No relevant data found."; } // Get the search query from index.php (GET parameter) $query = isset($_GET['query']) ? $_GET['query'] : ''; if ($query) { echo fetchFromWeb($query); // Output the result } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.3.24 | Generation time: 0.11 |
proxy
|
phpinfo
|
Settings