Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 56
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Prawdziwa skarbnica wiedzy na temat tworzenia stron WWW i nie tylko. Korzystam z porad praktycznie codziennie, jest mi to niezbędne w mojej pracy. Sam zajmuję się tworzeniem serwisów, ale porady pisane przez Darka sa dla mnie nieocenioną pomocą! Proste, czytelne i zrozumiałe dla każdego! Czekam na więcej!

Krzysztof Szypulski
KESS - projektowanie stron

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

CVI. GNU Readline

Wstęp

Funkcje readline() implementują interfejs do biblioteki GNU Readline. Funkcje te pozwalają na tworzenie edytowalnych linii poleceń. Jako przykład może posłużyć Bash, który pozwala na używanie klawiszy strzałek do poruszania się po wpisanej części polecenia lub przewijanie historii. Ze względu na interaktywność tej biblioteki, nie przyda się ona do pisania aplikacji sieciowych, lecz może być przydatna przy pisaniu skryptów przeznaczonych do użycia PHP z linii poleceń.

Notatka: To rozszerzenie nie jest dostępne na platformie Windows.

Wymagania

Aby korzystać z funkcji readline niezbędne jest zainstalowanie biblioteki libreadline. Bibliotekę libreadline można znaleźć na stronie domowej projektu GNU Readline, http://cnswww.cns.cwru.edu/~chet/readline/rltop.html Jest ona obsługiwana przez Cheta Ramey'a, który jest także autorem Basha.

Z funkcji tych można skorzystać także przy użyciu biblioteki libedit, zamiennika biblioteki readline, wydanego na licencji innej niż GPL. Biblioteka libedit jest wydana na licencji BSD i można ją znaleźć pod adresem http://sourceforge.net/projects/libedit/.

Instalacja

To use these functions you must compile the CGI or CLI version of PHP with readline support. You need to configure PHP --with-readline[=DIR]. In order you want to use the libedit readline replacement, configure PHP --with-libedit[=DIR].

Konfiguracja czasu wykonywania

To rozszerzenie nie definiuje posiada żadnych dyrektyw konfiguracyjnych w pliku php.ini.

Typy zasobów

To rozszerzenie nie posiada żadnych rodzajów zasobów.

Stałe predefinopwane

To rozszerzenie nie posiada żadnych stałych.

Spis treści
readline_add_history -- Dodaje linię do historii
readline_callback_handler_install -- Initializes the readline callback interface and terminal, prints the prompt and returns immediately
readline_callback_handler_remove -- Removes a previously installed callback handler and restores terminal settings
readline_callback_read_char -- Reads a character and informs the readline callback interface when a line is received
readline_clear_history -- Czyści historię
readline_completion_function -- Rejestruje funkcję dopełniania
readline_info -- Pobiera/ustawia różne wewnętrzne zmienne readline'a
readline_list_history -- Zwraca listę historii
readline_on_new_line --  Inform readline that the cursor has moved to a new line
readline_read_history -- Czyta historię
readline_redisplay --  Ask readline to redraw the display
readline_write_history -- Zapisuje historię
readline -- Czyta linię



User Contributed Notes

jeffrey at thompsonic dot com
22-Feb-2005 03:18

Here's an easy way without readline() if you don't have it compiled in already:

   $fp = fopen("php://stdin","r");
   $line = rtrim(fgets($fp, 1024);


jcl atNOSPAM jcl dot name
23-Nov-2004 06:40

Even better than 'plz at dont dot spam' in only one line :) :

@c:\\php\\cli\\php.exe script.php %*

Cheers,
Jean-Charles


plz at dont dot spam
08-Aug-2004 10:50

To get all arguments passed to a batch file in one variable
rather than using %1 %2 %3 etc;

:LOOP
if "%1" == "" goto DONE
set args=%args% %1
shift
goto LOOP
:DONE
@c:\\php\\cli\\php.exe script.php %args%
set args=


ds at NOSPAM dot undesigned dot org dot za
05-Dec-2003 05:04

You can open /dev/tty on unix systems or \con in windows, with ob_implicit_flush(true) to write output unbuffered.  Works like a charm :-)

-------------------------------

#!/usr/local/bin/php -q
<?php

set_time_limit
(0);
@
ob_end_flush();
ob_implicit_flush(true);

class
prompt {
  var
$tty;

  function
prompt() {
   if (
substr(PHP_OS, 0, 3) == "WIN") {
    
$this->tty = fOpen("\con", "rb");
   } else {
     if (!(
$this->tty = fOpen("/dev/tty", "r"))) {
      
$this->tty = fOpen("php://stdin", "r");
     }
   }
  }

  function
get($string, $length = 1024) {
   echo
$string;
  
$result = trim(fGets($this->tty, $length));
   echo
"\n";
   return
$result;
  }
}

echo
"Enter something or 'exit' to quit\n";
do {
 
$cmdline = new prompt();
 
$buffer = $cmdline->get("Something: ");
  echo
"You said: $buffer\n";
} while (
$buffer !== "exit");
echo
"Goodbye\n";

?>


jewfish at jewfish dot net
11-Jun-2002 01: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;
}


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

Here's an example simple readline-like way to input from command line on windows - the single line is from http://www.phpbuilder.com/columns/darrell20000319.php3, 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");
?>


14-Apr-2002 04: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


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt