Previous Thread
Next Thread
Print Thread
Rate Thread
#221757 07/27/2002 1:54 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
I needed to write a simple PHP utility script for importing my UBB.classic avatars into UBB.threads. I prefer running such scripts from the shell (command line), so I don't have to deal with CGI timeouts, etc. I could have used Perl instead, but I'm missing the Perl DBI module for interfacing with MySQL, and didn't want to mess with installing it right now.

You would think that reading and writing stuff to the console would be easy (as it is in Perl or C), but it took me a couple of hours to figure out how to do it in PHP. There were mainly two things I had to do:

1) Call ob_implicit_flush() before doing any I/O. This causes the output buffer to be automatically flushed each time output is performed.

2) Explicitly open standard input. Here's a function I wrote for doing the input. The function readline() supposedly does about the same thing, but that's apparently part of an add-on module that has to be compiled into PHP.
code:
// Output a prompt string to the console,
// and get the (whitespace-trimmed) response.

function getline($prompt) {

echo $prompt;
$fp = fopen('php://stdin', 'r') or die("fopen(stdin)\n");
$line = fgets($fp, 1024);
fclose($fp);
return trim($line);
}



If anyone knows an easier way of doing this, please correct me.

Sponsored Links
Entire Thread
Subject Posted By Posted
Console I/O Dave_L_dup1 07/27/2002 8:54 PM
Re: Console I/O Gardener 07/29/2002 8:40 PM
Re: Console I/O Dave_L_dup1 07/30/2002 11:40 PM
Re: Console I/O Gardener 07/31/2002 2:51 AM

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
• Shock Hosting
• Stable Host
• bluehost
• InterServer
Visit us on Facebook
Member Spotlight
Bill B
Bill B
Issaquah, WA
Posts: 87
Joined: December 2001
Forum Statistics
Forums63
Topics37,583
Posts293,955
Members13,825
Most Online151,614
Nov 14th, 2025
Today's Statistics
Currently Online 133007
Topics Created 0
Posts Made 0
Users Online 1
Birthdays 11
Top Posters
AllenAyres 21,080
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,834
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2026 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.1.0
(Snapshot build 20260108)