Jump to content

Recommended Posts

Hi All,

 

Hope I can get some help from you here. I am using command line, and the following script works fine.

 

Problem 1:

I would like to have a link or call function to these sites below(in the same script if possible), like if the user picks 'b' (Site2), then this script can  point to the specific item.

I have additional PHP scripts such as config.php, download.php. How can I include download.php in this script to be called automatically when the user makes a choice.

The choice comes first and then download follows.

 

 

Problem 2:

How to insert error handler in this script? Like if the user mistakenly input a wrong choice...eg: m instead of c.

 

Hope to get some comments soon...

thanks in advance for reading!

 

<?php 
fwrite(STDOUT, "Pick a site link  (enter the letter and press return)\n"); 
// An array of choice to sites 
$sites = array ( 
   'a'=>'Site1', 
   'b'=>'Site2', 
   'c'=>'Site3',
   'd'=>'Site3',

); 

fwrite(STDOUT, "Enter 'q' to quit\n"); 

// Display the choices 
foreach ( $sites as $choice => $site ) { 
   fwrite(STDOUT, "\t$choice: $site\n"); 
} 

// Loop until they enter 'q' for Quit 
do { 
   // A character from STDIN, ignoring whitespace characters 
   do { 
       $selection = fgetc(STDIN); 
   } while ( trim($selection) == '' ); 

   if ( array_key_exists($selection,$sites) ) { 
       fwrite(STDOUT, "You picked {$sites[$selection]}\n"); 
   } 

} while ( $selection != 'q' ); 

exit(0); 
?>

Link to comment
https://forums.phpfreaks.com/topic/67295-solved-php-script-expension/
Share on other sites

Well include could be part of it...but I would like the following order to take place:

 

1- user chooses a site first

2- download begins after that choice.

 

I wish i could use include() but I am afraid this will start first before the user makes a choice of which site to navigate. So how to do that ?

 

hope this is clearer....

thanks again...

Hi again,,,

 

Is it possible to combine array and echo or print together?????

 

 

I would like to use echo or print in the array....how to go about that?

 

Like once all the sites are displayed, there could be one line description of each one of them.

The result shoud look like this:

 

Enter 'q' to quit

a: sites {one line description goes here....} but how?

b: site2 {one line description goes here....} "

c: site3 {another line description goes here....} but how?

d: site4 {another line description goes here....} "

e: site5 {another line description goes here....} "

 

 

thanks...!

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.