Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-21-2003, 10:44 AM   #1 (permalink)
Antagony
Registered User
 
Antagony's Avatar
 
Join Date: Mar 2003
Posts: 31
Antagony is on a distinguished road
Send a message via ICQ to Antagony
PHP Command-Line Arguments?

I use PHP in a linux environment, and as such, I have use of the command-line interface, e.g. "# php crap.php"

I was wondering if it was possible to pass command-line arguments to a php script, e.g. "# php crap.php http://www.codenewbie.com"

Is that possible? If so, what environment variables do I need to look at?

Thanks.
Antagony is offline   Reply With Quote
Old 04-21-2003, 11:24 AM   #2 (permalink)
Antagony
Registered User
 
Antagony's Avatar
 
Join Date: Mar 2003
Posts: 31
Antagony is on a distinguished road
Send a message via ICQ to Antagony
Okay, I answered my own question.

If you've used C/C++, then you'll pick this up easily. There are two variables, "$argc" and "$argv".

$argc is "argument counter". It's an integer that represents the number of arguments passed to the script PLUS ONE (the name of the script being executed).

Example, "# php crap.php crap rocks"
$argc would hold the value "3".

$argv is "argument value". It's an array that contains an argument (as a string) in each array key, with the name of the script being in $argv[0] and the arguments passed being held after that.

Example, "# php crap.php crap rocks"
$argv[0] = "crap.php"
$argv[1] = "crap"
$argv[2] = "rocks"

Make sense? I'm pretty sure that's how things go anyway, I haven't actually typed out any code for it yet, but I'm about to do so. So if I'm wrong, I'll come back and fix this post
Antagony is offline   Reply With Quote
Old 04-21-2003, 12:14 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
that is great question/answer! i was searching for an answer, and then i found it here =)

that is correct info too according to other sources. :rock:
__________________
Mike
sde is offline   Reply With Quote
Old 05-02-2003, 01:26 PM   #4 (permalink)
Antagony
Registered User
 
Antagony's Avatar
 
Join Date: Mar 2003
Posts: 31
Antagony is on a distinguished road
Send a message via ICQ to Antagony
Glad you found it useful
Antagony is offline   Reply With Quote
Old 09-24-2009, 08:46 AM   #5 (permalink)
bisnaguete
Recruit
 
Join Date: Sep 2009
Posts: 1
bisnaguete is on a distinguished road
Useful for me too, thnx =)

Very direct and precise.
bisnaguete is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Comes of Age sde Code Newbie News 0 04-14-2004 12:41 PM
new to php jhoop2002 PHP 12 08-06-2003 03:45 PM
I need to learn PHP Nitro PHP 9 06-28-2003 12:24 PM
Php Vs. Asp sde PHP 6 06-06-2003 07:02 PM
PHP as CGI?? bdl PHP 8 05-08-2003 09:29 AM


All times are GMT -8. The time now is 04:31 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting