How can one effectively analyze the HTML response from a music website to determine successful and unsuccessful searches for lyrics using PHP?

To effectively analyze the HTML response from a music website to determine successful and unsuccessful searches for lyrics using PHP, you can use PHP's DOMDocument class to parse the HTML and extract the relevant information. You can then look for specific elements or patterns in the HTML response to identify successful searches (such as the presence of lyrics) or unsuccessful searches (such as error messages).

<?php
// Assume $htmlResponse contains the HTML response from the music website

$dom = new DOMDocument();
$dom->loadHTML($htmlResponse);

// Check for successful search by looking for lyrics element
$lyricsElement = $dom->getElementById('lyrics');
if ($lyricsElement) {
    echo "Lyrics found!";
} else {
    // Check for unsuccessful search by looking for error message element
    $errorMessageElement = $dom->getElementById('error-message');
    if ($errorMessageElement) {
        echo "Search unsuccessful. Error message: " . $errorMessageElement->textContent;
    } else {
        echo "Search unsuccessful. No lyrics found.";
    }
}
?>