How can PHP scripts be structured to handle form inputs and display search results in a user-friendly manner?

To handle form inputs and display search results in a user-friendly manner, you can structure your PHP script by first checking if form data has been submitted. If form data is present, process the input and perform the search query. Then, display the search results in a formatted way on the webpage. This can be achieved by using HTML to structure the output and CSS for styling.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data and perform search query
    $search_query = $_POST['search_query'];
    
    // Display search results
    echo "<div class='search-results'>";
    echo "<h2>Search Results for: $search_query</h2>";
    // Perform search query and display results here
    echo "</div>";
}
?>

<html>
<head>
    <style>
        .search-results {
            background: #f9f9f9;
            padding: 10px;
            margin: 10px;
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="text" name="search_query" placeholder="Enter search query">
        <button type="submit">Search</button>
    </form>
</body>
</html>