How can PHP be used to create a form for users to input search queries and redirect them to a search engine like Google?

To create a form for users to input search queries and redirect them to a search engine like Google using PHP, you can create a simple HTML form that takes the user's query as input. Upon submission, the PHP script can then redirect the user to a Google search URL with the user's query as a parameter.

<?php
if(isset($_POST['search_query'])){
    $query = urlencode($_POST['search_query']);
    header("Location: https://www.google.com/search?q=$query");
    exit();
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Search Form</title>
</head>
<body>
    <form method="post" action="">
        <input type="text" name="search_query" placeholder="Enter your search query">
        <input type="submit" value="Search">
    </form>
</body>
</html>