prepare($sql); $searchTerm = '%' . $search . '%'; $stmh->bindParam(':search1', $searchTerm, PDO::PARAM_STR); $stmh->execute(); $output_rows = $stmh->fetchAll(PDO::FETCH_ASSOC); // Function to normalize strings: remove spaces, special characters and convert to lowercase function normalize($str) { return strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $str)); } // Remove duplicate rows based on 'phone', 'outputplace', 'outworkplace', 'receiver' columns $unique_rows = []; $seen = []; foreach ($output_rows as $row) { $normalized_phone = normalize($row['phone']); $normalized_outputplace = normalize($row['outputplace']); $normalized_outworkplace = normalize($row['outworkplace']); $normalized_receiver = normalize($row['receiver']); $key = $normalized_phone . '|' . $normalized_outputplace . '|' . $normalized_outworkplace . '|' . $normalized_receiver; if (!isset($seen[$key])) { $unique_rows[] = $row; $seen[$key] = true; } } // Output the results as JSON header('Content-Type: application/json'); echo json_encode($unique_rows); } catch (PDOException $Exception) { // Output the error message as JSON header('Content-Type: application/json'); echo json_encode(["error" => $Exception->getMessage()]); exit; } ?>