<?php
// File: find_senior_competitions.php
// Function to fetch the webpage content
function fetchWebPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Skip SSL verification for simplicity
$content = curl_exec($ch);
if (curl_errno($ch)) {
die("cURL error: " . curl_error($ch));
}
curl_close($ch);
return $content;
}
// Function to parse and find senior competitions in the page
function findSeniorCompetitions($htmlContent) {
$dom = new DOMDocument();
libxml_use_internal_errors(true); // Suppress parsing warnings
$dom->loadHTML($htmlContent);
libxml_clear_errors();
$xpath = new DOMXPath($dom);
$results = [];
// Search for text containing "senior" in various tags
$nodes = $xpath->query("//*[contains(text(), 'senior')]");
foreach ($nodes as $node) {
$results[] = trim($node->nodeValue);
}
return $results;
}
// Main script
$url = "https://new.easthampsteadgolfclub.co.uk/about-easthampstead-mens-golf-club/mens-calendar/"; // Replace with the target URL
$htmlContent = fetchWebPage($url);
$competitions = findSeniorCompetitions($htmlContent);
if (!empty($competitions)) {
echo "Senior Competitions Found:\n";
foreach ($competitions as $competition) {
echo "- $competition\n";
}
} else {
echo "No senior competitions found on the webpage.\n";
}
?>