Программирование > PHP

Как передать проге на РНР параметр извне?

(1/1)

serg128:
Суть вот какая: надо запускать прогу так:
C:\\php\\php.exe myprog.php file.txt
Так вот параметр file.txt надо как то передать программе. Как?

for_i_0:
может все таки открыть file.txt и прочесть его в myprog.php?

CGVictor:
for_i_0
Ему надо строку вызова читать. Как мне показалось. Т.е. скрипт об этом file.txt даже не обязан подозревать.

serg128
http://ru2.php.net/manual/ru/reserved.variables.php

--- Цитировать ---\'argv\'
    Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.
\'argc\'
    Contains the number of command line parameters passed to the script (if run on the command line).
--- Конец цитаты ---

justcoder:
Совершенно согласен с предыдущим оратором.
Пишешь:

if ($argc != 2 )
 die (\'usage \'.$argv[0].\' <filename>\'."\\n");

$filename = $argv[1];
if (! is_file($filename))
 die ($filename.\' is not a file\' . "\\n");

# ... и тут понеслась... $filename - имя файла.

Навигация

[0] Главная страница сообщений

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
Перейти к полной версии