note 56217 added to function.readline
| From: | Vylen at osu1 dot php dot net | Date: | Sat, 27 Aug 2005 15:36:59 +0000 |
| Subject: | note 56217 added to function.readline | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94262@lists.php.net to get a copy of this message | ||
I've got another solution for those those without readline compiled on a linux system.
This one is different as it is specifically for different PHP files opened by proc_open or in the
CLI and are constantly looking for input.
<?php
// Define the pointer
$readline = popen("while true; do { read reply; echo \$reply ; }; done", "r");
// Some class
class example {
function data() {
global $readline;
// Return any data from $readline, substr() is to remove the trailing linebreak, its really
optional.
return(substr(fgets($readline, 1024), 0, -1));
}
}
$example = new example();
while($line = $example->data()) {
if($line == 'hello')
echo "Hi to you too!\n";
else
echo "recieved input\n";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.readline.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56217
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56217&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56217&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56217&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56217&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56217&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56217&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56217&report=yes
Search -- http://master.php.net/manage/user-notes.php