Hướng dẫn where is php command line? - dòng lệnh php ở đâu?

16 tháng 9 tại PSU DOT EDU ¶

10 năm trước

You can easily parse command line arguments into the $_GET variable by using the parse_str() function.

<?php

parse_str

(implode('&', array_slice($argv, 1)), $_GET);?>

It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

Ẩn danh ¶

1 năm trước

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal:

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.

Apmuthu tại USA DOT NET

4 năm trước

Adding a pause() function to PHP waiting for any user input returning it:

<?php0

Drewish tại Kindahouse dot com ¶

17 năm trước

<?php2

<?php3

<?php4

Franknospamwanted tại. Toppoint Dot. de ¶

7 năm trước

<?php6

<?php7

<?php8

<?php9

Lucas Dot Vasconcelos tại Gmail Dot Com ¶

15 năm trước

parse_str1

parse_str2

parse_str3

Monte at ispi dot net ¶

19 năm trước

parse_str5

parse_str6

OHCC tại 163 dot com ¶

6 năm trước

parse_str8

parse_str9

(implode('&', array_slice($argv, 1)), $_GET);?>

It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

0

notrealllyanaddress tại Somerandomaddr dot com ¶

12 năm trước

(implode('&', array_slice($argv, 1)), $_GET);?>

It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

2

(implode('&', array_slice($argv, 1)), $_GET);?>

It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

3

Sam Marshall ¶

3 năm trước

(implode('&', array_slice($argv, 1)), $_GET);?>

It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

5

(implode('&', array_slice($argv, 1)), $_GET);?>

It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

6

(implode('&', array_slice($argv, 1)), $_GET);?>

It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

7

(implode('&', array_slice($argv, 1)), $_GET);?>

It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

8

Psikyo tại mail dot dlut dot edu dot cn ¶

9 năm trước

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv
0

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv
1

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv
2

ben tại slax0rnet dot com

18 năm trước

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv
4

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv
5

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv
6

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv
7

We can pass many arguments directly into the hashbang line.
As example many ini setting via the -d parameter of php.
---
#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
phpinfo();
exit;
---
./script | grep memory
memory_limit => 2048M => 2048M
---
But we can also use this behaviour into a second script, so it call the first as an interpreter, via the hashbang:
---
#!./script arg1 arg2 arg3
---
However the parameters are dispatched in a different way into $argv
8

Kodeart ¶

11 năm trước

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.0

Overflow636 tại Gmail Dot Com ¶

17 năm trước

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.1

Franknospamwanted tại. Toppoint Dot. de ¶

7 năm trước

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.2

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.3

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.4

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.5

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.6

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.7

Ẩn danh ¶

12 năm trước

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.8

Sam Marshall ¶

15 năm trước

All the parameters are in $argv[1], $argv[0] is the interpreter script name, and $argv[1] is the caller script name.9

Monte at ispi dot net ¶

17 năm trước

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 0

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 1

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 2

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 3

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 4

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 5

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 6

Franknospamwanted tại. Toppoint Dot. de ¶

7 năm trước

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 8

To get back the parameters into $argv, we can simply test if $argv[1] contains spaces, and then dispatch again as normal: 9

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.
0

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.
1

Lucas Dot Vasconcelos tại Gmail Dot Com ¶

7 năm trước

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.
3

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.
4

Lucas Dot Vasconcelos tại Gmail Dot Com ¶

15 năm trước

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.
6

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.
7

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.
8

Monte at ispi dot net ¶

15 năm trước

#!/usr/bin/php -d memory_limit=2048M -d post_max_size=0
<?php
var_dump
($argv);
if (
strpos($argv[1], ' ') !== false){
 
$argw = explode(" ", $argv[1]);
 
array_unshift($argw, $argv[2]);
 
$argv = $argw;
}
var_dump($argv); ?>
---
array(3) {
  [0]=>
  string(8) "./script"
  [1]=>
  string(15) "arg1 arg2 arg3 "
  [2]=>
  string(14) "./other_script"
}
array(4) {
  [0]=>
  string(8) "./other_script"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}
---
This will maintain the same behaviour in all cases and allow to even double click a script to call both parameters of another script, and even make a full interpreter language layer.  The other script doesn't has to be php. Take care of paths.
9

0

1

2

Monte at ispi dot net ¶

15 năm trước

4

5

6

7

Monte at ispi dot net ¶

19 năm trước

8

9

Adding a pause() function to PHP waiting for any user input returning it:0

Adding a pause() function to PHP waiting for any user input returning it:1

OHCC tại 163 dot com ¶

15 năm trước

Adding a pause() function to PHP waiting for any user input returning it:3

Adding a pause() function to PHP waiting for any user input returning it:4

Adding a pause() function to PHP waiting for any user input returning it:5

Adding a pause() function to PHP waiting for any user input returning it:6

Monte at ispi dot net ¶

18 năm trước

Adding a pause() function to PHP waiting for any user input returning it:8

Adding a pause() function to PHP waiting for any user input returning it:9

Kodeart ¶

17 năm trước

<?php01

<?php02

<?php03

<?php04

<?php05

<?php06

<?php07

<?php08

<?php09

<?php10

<?php11

Franknospamwanted tại. Toppoint Dot. de ¶

7 năm trước

<?php13

Lucas Dot Vasconcelos tại Gmail Dot Com ¶

19 năm trước

<?php14

<?php15

<?php16

<?php17

<?php18

OHCC tại 163 dot com ¶

6 năm trước

<?php20

<?php21

<?php22

<?php23

<?php24

<?php25

<?php26

<?php27

<?php28

<?php29

<?php30

<?php31

<?php32

<?php33

<?php34

<?php35

notrealllyanaddress tại Somerandomaddr dot com ¶

19 năm trước

<?php37

<?php38

<?php39

<?php40

OHCC tại 163 dot com ¶

17 năm trước

<?php42

<?php43

<?php44

<?php45

<?php46

<?php47

<?php48

Franknospamwanted tại. Toppoint Dot. de ¶

15 năm trước

<?php50

<?php51

Monte at ispi dot net ¶

15 năm trước

<?php53

Tôi chạy các lệnh PHP ở đâu?

Bạn chỉ cần làm theo các bước để chạy chương trình PHP bằng dòng lệnh ...
Mở cửa sổ thiết bị đầu cuối hoặc dòng lệnh ..
Goto thư mục hoặc thư mục được chỉ định có các tệp PHP có mặt ..
Sau đó, chúng ta có thể chạy mã PHP bằng lệnh sau: php file_name.php ..

Lệnh php CLI là gì?

Tính đến phiên bản 4.3.0, PHP hỗ trợ loại SAPI mới (Giao diện lập trình ứng dụng máy chủ) có tên CLI có nghĩa là giao diện dòng lệnh.Đúng như tên gọi, trọng tâm chính của loại SAPI này là phát triển các ứng dụng Shell (hoặc máy tính để bàn) với PHP.Command Line Interface. As the name implies, this SAPI type main focus is on developing shell (or desktop as well) applications with PHP.

Làm thế nào để tôi biết nếu PHP đang chạy CMD?

Để phát hiện xem tập lệnh PHP của bạn có được gọi qua máy khách web hoặc qua CLI hay không, bạn có thể sử dụng chức năng PHP_SAPI_NAME.Nếu bạn sử dụng mã đơn giản này: echo php_sapi_name ();use the php_sapi_name function. If you use this simple code: echo php_sapi_name();

Làm cách nào để truy cập PHP?

Nếu bạn muốn chạy nó, hãy mở bất kỳ trình duyệt web nào và nhập vào localhost/demo.php và nhấn enter.Chương trình của bạn sẽ chạy.open any web browser and enter “localhost/demo. php” and press enter. Your program will run.