Homestar Runner Wiki Forum

A companion to the Homestar Runner Wiki
It is currently Sat Aug 23, 2025 3:51 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: I should probably ask this on a programming forum, but...
PostPosted: Sat May 24, 2008 5:09 pm 
Offline
User avatar

Joined: Wed Jul 27, 2005 2:31 pm
Posts: 845
Location: Looking for a new avatar
...just in case,
I'm in the process of learning php (which is surprisingly similar to GML)
and, I have a "compiler" for php on my computer. Now, I know PHP
is intended to be interpreted on an online host, but I also want to write
stand-alone programs using it. Is there anyway to get input/output in it?
Like, the same way you would in BASIC? Here's the BASIC equivilent of what
I want to do:
Code:
print "how much do you want to bet?"
input bet

How would I do such a thing in PHP? And don't say "use an HTML forum!", I
am trying to make this a stand-alone application.
PS: sorry for all of these questions! If I can't find help here, I'll ask it on a
Tech forum.

_________________
Alright! You win, The Noid! No more memes.


Top
 Profile  
 
 Post subject: Re: I should probably ask this on a programming forum, but...
PostPosted: Mon May 26, 2008 2:41 pm 
Offline
User avatar

Joined: Sun Apr 15, 2007 7:20 pm
Posts: 2321
Location: Strawberries. :[
I'm not too sure how to apply PHP to a command line application, but from what I've read you can use fwrite/fgets and stuff like that to output and input information. Normally you'd say something like fwrite($fileHandle, 'String'); to write 'String' to a file, but in this case you'd write 'String' to $STDOUT to write to the prompt.

<?php
$STDOUT = fopen('php://stdout', 'w');
$STDIN = file_get_contents('php://stdin', 'r');
fwrite($STDOUT, 'How much do you wanna bet? ');
$bet = fgets($STDIN);
?>

Not totally sure if that would work 'cause I don't have too much time to look into the subject.

Why do you want to use PHP as a desktop scripting language?


Top
 Profile  
 
 Post subject: Re: I should probably ask this on a programming forum, but...
PostPosted: Mon May 26, 2008 4:20 pm 
Offline
User avatar

Joined: Tue Jan 18, 2005 1:37 am
Posts: 2035
Location: All the way on the other side of the internet. Really.
PHP is for internet.

Why the heck would you do otherwise?

_________________
Image


Top
 Profile  
 
 Post subject: Re: I should probably ask this on a programming forum, but...
PostPosted: Mon May 26, 2008 7:31 pm 
Offline
User avatar

Joined: Sun Apr 15, 2007 7:20 pm
Posts: 2321
Location: Strawberries. :[
The only real feasible need for a command line PHP script would be a cron job. But even then, that would probably just need arguments instead of asking for input. In which case input would be like:

php myscript.php Mike

Code:
<?php
$name = $_SERVER['argv'][1]; //0 => myscript.php; 1 => Mike
print "Hello there, $name!";
?>


Top
 Profile  
 
 Post subject: Re: I should probably ask this on a programming forum, but...
PostPosted: Thu May 29, 2008 8:26 pm 
Offline
User avatar

Joined: Mon Jul 05, 2004 1:57 am
Posts: 2981
Location: Oklahoma City
Using PHP as anything other than a web language is, frankly, a horrible idea. You're suffering from the "When all you have is a hammer, everything begins to look like a nail" syndrome. Learn a language like Python or Ruby; they're much better for developing computer programs than PHP is, and if you're comfortable with PHP, you'll be just as comfortable with them.

- Kef

_________________
404 sig not found


Top
 Profile  
 
 Post subject: Re: I should probably ask this on a programming forum, but...
PostPosted: Sat May 31, 2008 6:08 pm 
Offline
User avatar

Joined: Wed Jul 27, 2005 2:31 pm
Posts: 845
Location: Looking for a new avatar
furrykef wrote:
Using PHP as anything other than a web language is, frankly, a horrible idea. You're suffering from the "When all you have is a hammer, everything begins to look like a nail" syndrome. Learn a language like Python or Ruby; they're much better for developing computer programs than PHP is, and if you're comfortable with PHP, you'll be just as comfortable with them.

- Kef

Actually, I'm doing this so I can test scripts before I put them on the internet.

_________________
Alright! You win, The Noid! No more memes.


Top
 Profile  
 
 Post subject: Re: I should probably ask this on a programming forum, but...
PostPosted: Sat May 31, 2008 6:25 pm 
Offline
User avatar

Joined: Sun Apr 15, 2007 7:20 pm
Posts: 2321
Location: Strawberries. :[
Just stick it up on the Internet and use $_GET['name'] to test different variables.

script.php?name=Mike&age=17

$_GET['name'] would be 'Mike' and $_GET['age'] would be '17'. If you wanted to test different variables you can just change the URL.


Top
 Profile  
 
 Post subject: Re: I should probably ask this on a programming forum, but...
PostPosted: Sun Jun 01, 2008 5:01 pm 
Offline
User avatar

Joined: Mon Jul 05, 2004 1:57 am
Posts: 2981
Location: Oklahoma City
strongfan wrote:
Actually, I'm doing this so I can test scripts before I put them on the internet.


In that case you shouldn't make a standalone script. What you should do is install Apache on your computer and make a mini-website that you can use to test exactly the same script you would upload on the web. Or, much easier, you could just put a test site on the web and use that...

- Kef

_________________
404 sig not found


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group