How can a full-text search be implemented in a website without searching through a database using PHP?

Implementing a full-text search in a website without searching through a database using PHP can be achieved by storing the text content of the website in a text file or an array, and then searching through this data using PHP functions like strpos or preg_match. This method can be useful for smaller websites or when database access is not possible or necessary.

<?php
// Store text content in an array
$textContent = [
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    "Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
    "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
];

// Perform full-text search
$searchTerm = "ipsum";
$results = [];
foreach ($textContent as $text) {
    if (strpos($text, $searchTerm) !== false) {
        $results[] = $text;
    }
}

// Display search results
foreach ($results as $result) {
    echo $result . "<br>";
}
?>