How can PHP be used to perform an exact word search in a CSV file?

When performing an exact word search in a CSV file using PHP, we can read the file line by line and check if the desired word exists in each line. To ensure an exact match, we can use regular expressions or string comparison functions. By looping through the lines of the CSV file and comparing each line to the search term, we can identify and extract the exact matches.

<?php

$searchTerm = "example"; // Word to search for
$csvFile = "data.csv"; // Path to the CSV file

if (($handle = fopen($csvFile, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        foreach ($data as $value) {
            if (strpos($value, $searchTerm) !== false) {
                echo "Found exact match: " . $value . "\n";
            }
        }
    }
    fclose($handle);
}

?>