loadHTML($response); // Create a DOMXPath object $xpath = new DOMXPath($dom); // Find the first tag after

$existsNode = $xpath->query('//p[@class="mw-search-exists"]'); if ($existsNode->length > 0) { $linkNode = $xpath->query('.//following-sibling::a[1]', $existsNode->item(0)); if ($linkNode->length > 0) { $link = "https://yugioh.fandom.com" . $linkNode->item(0)->getAttribute('href'); echo '' . $link . ''; echo ''; } else { echo "Link not found."; } } else { echo "Search result exists not found."; } } ?>