PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > PHP CLI: Sending parameters via command line
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
PHP CLI: Sending parameters via command line

Réponse
 
LinkBack Outils de la discussion
Vieux 27/03/2008, 19h14   #1
Defranco
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut PHP CLI: Sending parameters via command line

Hi all,

How do a run a .php file via shell script (CLI ) but providing
parameters?

For example to run foo.php in unix I run the command:

php foo.php

But how do I pass parameters like in web interface: foo.php?
param1=value&param2=value2 via command Line?

The command:

php foo.php?arg1=value&arg2=value2

Will not work and the just explain how to pass arguments that I
understand that is not parameters like in web - I can not modify
foo.php to make it get arguments, only standard web parameters
(retrieved via $_GET ).

Thanks

Erico
  Réponse avec citation
Vieux 27/03/2008, 20h01   #2
Defranco
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP CLI: Sending parameters via command line

I'm not interested in passing arguments ($argv[]), but parameters
($_GET[]):

if I do it like web:
www.xxx.com/foo.php?name=Erico$age=33

I will get Erico as result for $_GET['name']

but how I do the same for this same script via CLI as I can not change
foo.php?

it will not work if I send arguments:

php foo.php name=Erico age=33

as arguments will fill $argv[] but $_GET[] will be empty.
  Réponse avec citation
Vieux 27/03/2008, 20h27   #3
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP CLI: Sending parameters via command line

Defranco wrote:
> Hi all,
>
> How do a run a .php file via shell script (CLI ) but providing
> parameters?
>
> For example to run foo.php in unix I run the command:
>
> php foo.php
>
> But how do I pass parameters like in web interface: foo.php?
> param1=value&param2=value2 via command Line?
>
> The command:
>
> php foo.php?arg1=value&arg2=value2
>
> Will not work and the just explain how to pass arguments that I
> understand that is not parameters like in web - I can not modify
> foo.php to make it get arguments, only standard web parameters
> (retrieved via $_GET ).
>
> Thanks
>
> Erico
>


Just like you pass PHP arguments (like the script name):

php script.php arg1 arg2 arg3

php -? provides this information.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 28/03/2008, 00h29   #4
Lars Eighner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP CLI: Sending parameters via command line

In our last episode,
<6f926bc9-27c9-4c1f-a8f1-077cf2d1775a@e6g2000prf.googlegroups.com>, the
lovely and talented Defranco broadcast on comp.lang.php:

> I'm not interested in passing arguments ($argv[]), but parameters
> ($_GET[]):


> if I do it like web:
> www.xxx.com/foo.php?name=Erico$age=33


> I will get Erico as result for $_GET['name']


> but how I do the same for this same script via CLI as I can not change
> foo.php?


> it will not work if I send arguments:


> php foo.php name=Erico age=33


> as arguments will fill $argv[] but $_GET[] will be empty.


That's right. It is a command line interface (CLI). There is no GET.

--
Lars Eighner <http://larseighner.com/> usenet@larseighner.com
Countdown: 298 days to go.
  Réponse avec citation
Vieux 28/03/2008, 01h35   #5
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP CLI: Sending parameters via command line

Defranco wrote:
> I'm not interested in passing arguments ($argv[]), but parameters
> ($_GET[]):
>
> if I do it like web:
> www.xxx.com/foo.php?name=Erico$age=33
>
> I will get Erico as result for $_GET['name']
>
> but how I do the same for this same script via CLI as I can not change
> foo.php?
>
> it will not work if I send arguments:
>
> php foo.php name=Erico age=33
>
> as arguments will fill $argv[] but $_GET[] will be empty.
>


You can't. $_GET is strictly a webserver parameter.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 28/03/2008, 12h08   #6
Toby A Inkster
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP CLI: Sending parameters via command line

Jerry Stuckle wrote:

> You can't. $_GET is strictly a webserver parameter.


What you *could* do would be to prepend a little routine to your code
which checks to see if any parameters have been passed to $argc and parses
them into $_GET.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 22:26.]

Best... News... Story... Ever!
http://tobyinkster.co.uk/blog/2008/03/23/hypnotist/
  Réponse avec citation
Vieux 07/04/2008, 20h55   #7
Defranco
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP CLI: Sending parameters via command line

Thanks for the answers!

/defranco
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11513 seconds with 15 queries