What is the best practice for handling line breaks and paragraph separations when searching for specific text in PHP?

When searching for specific text in PHP, it is important to consider how line breaks and paragraph separations may affect the search results. One common approach is to normalize the text by removing any line breaks or extra spaces before performing the search. This ensures that the search query matches the text accurately regardless of formatting.

// Sample code to search for specific text after normalizing line breaks and paragraph separations

$text = "This is a sample text with line breaks and paragraph separations.";
$searchTerm = "sample text";

// Normalize the text by removing line breaks and extra spaces
$normalizedText = preg_replace('/\s+/', ' ', $text);

// Perform the search on the normalized text
if (strpos($normalizedText, $searchTerm) !== false) {
    echo "Text found!";
} else {
    echo "Text not found.";
}