PHP readline() Function Last Updated : 01 Aug, 2023 Comments Improve Suggest changes Like Article Like Report The readline() function is an inbuilt function in PHP that is used to read user input from the command line window. It provides a way to interactively prompt the user for input and capture their response as a string. Syntax: readline($prompt): string|falseParameters: This function accepts one parameter which is described below. $prompt: This is an optional parameter. This is the string parameter that is displayed when the user entered the command line interface.Return Value: The readline() function returns the provided string. This function will return false if no more data is found to be read. Program 1: The following program demonstrates the readline() function. PHP <?php // Simple example prompting the user for their name $name = readline("Enter your name: "); // Check if the user provided a name if ($name !== "") { echo "Hello, $name! Nice to meet you."; } else { echo "You didn't enter your name."; } ?> OutputEnter your name: Hello, ! Nice to meet you. Program 2: The following program demonstrates the readline() function. PHP <?php // Function to ask a question and get user input function askQuestion($question) { return readline($question . " "); } // Main program echo "Welcome to the Interactive Survey!\n"; echo "Please answer the following questions:\n"; // Ask the user some questions $name = askQuestion("1. What is your name?"); $age = askQuestion("2. How old are you?"); $location = askQuestion("3. Where are you from?"); $hobby = askQuestion("4. What is your favorite hobby?"); $feedback = askQuestion("5. How do you like this survey?"); // Display the survey results echo "\nSurvey Results:\n"; echo "Name: {$name}\n"; echo "Age: {$age}\n"; echo "Location: {$location}\n"; echo "Favorite Hobby: {$hobby}\n"; echo "Feedback: {$feedback}\n"; echo "\nThank you for participating in the survey!\n"; ?> Output: Welcome to the Interactive Survey!Please answer the following questions:1. What is your name? GFG2. How old are you? 203. Where are you from? India4. What is your favorite hobby? ID5. How do you like this survey? boredSurvey Results:Name: GFGAge: 20Location: IndiaFavorite Hobby: IDFeedback: boredThank you for participating in the survey!Reference: https://www.php.net/manual/en/function.readline.php Comment More infoAdvertise with us Next Article PHP | rewind( ) Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function Similar Reads PHP readfile( ) Function The readfile() function in PHP reads a file and writes its contents directly to the output buffer (usually the browser). Itâs an easy way to show a file without reading it line by line yourself.If thereâs a problem reading the file, like if it doesnât exist, PHP will usually show an error message. T 3 min read PHP readfile( ) Function The readfile() function in PHP reads a file and writes its contents directly to the output buffer (usually the browser). Itâs an easy way to show a file without reading it line by line yourself.If thereâs a problem reading the file, like if it doesnât exist, PHP will usually show an error message. T 3 min read PHP readfile( ) Function The readfile() function in PHP reads a file and writes its contents directly to the output buffer (usually the browser). Itâs an easy way to show a file without reading it line by line yourself.If thereâs a problem reading the file, like if it doesnât exist, PHP will usually show an error message. T 3 min read PHP | rewind( ) Function The rewind() function in PHP is an inbuilt function which is used to set the position of the file pointer to the beginning of the file. Any data written to a file will always be appended if the file is opened in append ("a" or "a+") mode regardless of the file pointer position. The file on which the 2 min read PHP | rewind( ) Function The rewind() function in PHP is an inbuilt function which is used to set the position of the file pointer to the beginning of the file. Any data written to a file will always be appended if the file is opened in append ("a" or "a+") mode regardless of the file pointer position. The file on which the 2 min read PHP | rewind( ) Function The rewind() function in PHP is an inbuilt function which is used to set the position of the file pointer to the beginning of the file. Any data written to a file will always be appended if the file is opened in append ("a" or "a+") mode regardless of the file pointer position. The file on which the 2 min read Like