PHP  
downloads | documentation | faq | getting help | | php.net sites | links 
search for in the  
previouspspell_suggestreadlinenext
Last updated: Tue, 11 Jun 2002
view this page in Printer friendly version | English | Brazilian Portuguese | Czech | Dutch | Finnish | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

LXXXIV. Readline (GNU)

Les fonctions readline() impl�mente une interface avec la librairie GNU Readline. Ces fonctions fournissent une ligne de commande �ditable, un peu comme lorsque Bash vous permet d'utiliser les fl�ches de d�placement pour ins�rer un caract�re ou passer en revue l'historique. A cause de l'interactivit� de ces commande, elles ne seront que rarement utiles pour les applications Web, mais peuvent se r�v�ler utiles lorsqu'un script est ex�cut� depuis une commande shell.

Le site du projet GNU Readline est . Elle est entretenue par Chet Ramey, qui est aussi l'auteur de Bash.

Table des mati�res
readline -- Lit une ligne
readline_add_history -- Ajoute une ligne � l'historique
readline_clear_history -- Efface l'historique
readline_completion_function -- Enregistre une fonction de compl�tion
readline_info -- Lit/modifie diverses variables internes
readline_list_history -- Liste l'historique
readline_read_history -- Lit l'historique
readline_write_history -- Ecrit dans l'historique
User Contributed Notes
Readline (GNU)
add a note about notes

04-Mar-2002 04:11

You'll probably need the --with-readline directive when configuring php to
have the readline() functions available.  

If you've installed the readline libraries in /usr/local, add:

--with-readline=/usr/local

to your ./configure command.

14-Apr-2002 01:17
[Ed. note: you can use fopen("php://stdin", "w") to
achieve the same thing, works on both Windows and Unix)]

I wanted to get console input in a PHP script running on windows, so I
made a little hack, which is so simple, it is clearly public domain.  What
I did was write a C++ program to get a line, then output it.  Then all
that is needed is to exec() that program and capture the output -
readline() for windows.  The C++ source is as follows:

#include <iostream.h>
#include <string>
void main()
{
    string input;
    cin >> input;
    cout << input;
}

It works wonderfully for my purposes, since I love the PHP language and
want to have console input.

Justin Henck

joshua at neocodesoftware.com
21-Apr-2002 09:17

Here's an example simple readline-like way to input from command line on
windows - the single line is from 
the multiline is something I added...

<?
function read () {
	# 4092 max on win32 fopen

	$fp=fopen("php://stdin", "r");
	$in=fgets($fp,4094);
	fclose($fp);

	# strip newline
	(PHP_OS == "WINNT") ? ($read = str_replace("\r\n",
"", $in)) : ($read = str_replace("\n", "",
$in));

	return $read;
}

function multilineread () {
	do {
		$in = read();

		# test exit
		if ($in == ".") return $read;

		# concat input
		(PHP_OS == "WINNT") ? ($read = $read . ($read ?
"\r\n" : "") . $in) : ($read = $read . "\n"
. $in);

	} while ($inp != ".");

	return $read;
}

print("End input with . on line by itself.\n");

print("What is your first name?\n");
$first_name = multilineread();

print("What is your last name?\n");
$last_name = read();

print("\nHello, $first_name $last_name! Nice to meet you! \n");
?>


10-Jun-2002 10:05

There is a simpler way to do a multiline read than above:

function multiline() {
    while(($in = readline("")) != ".")
        $story .= ($PHP_OS == "WINNT") ? "\r\n".$in :
                                         "\n".$in;

    return $story;
}

add a note about notes
previouspspell_suggestreadlinenext
Last updated: Tue, 11 Jun 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Mon Jul 8 08:17:45 2002 CEST