Home >Backend Development >PHP Problem >What are the three ways to pass parameters to php?
Three ways to pass parameters to php: 1. Use the "$argv" or "$argc" variable to pass parameters; 2. Use the getopt() function to pass in parameters, the syntax "getopt(' a:b:')"; 3. Use fwrite() and fgets() to pass in parameters through user input data.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Three ways to pass in parameters in php
1. Use $argv or $argc parameters to receive
<?php /** * 使用 $argc $argv 接受参数 */ echo "接收到{$argc}个参数"; print_r($argv);
The following are the results of the test
2. Use getopt function (this method is recommended)
<?php /** * 使用 getopt函数 */ $param_arr = getopt('a:b:'); print_r($param_arr);##3
. Input data through the user
<?php /** * 提示用户输入,类似Python */ fwrite(STDOUT,'please input:'); echo 'your input is:'.fgets(STDIN);The user’s input cannot be empty
<?php /** * 提示用户输入,类似Python */ $fs = true; do{ if($fs){ fwrite(STDOUT,'请输入您的博客名:'); $fs = false; }else{ fwrite(STDOUT,'抱歉,博客名不能为空,请重新输入您的博客名:'); } $name = trim(fgets(STDIN)); }while(!$name); echo '您输入的信息是:'.$name."\r\n";Recommended learning: "
PHP Video Tutorial"
The above is the detailed content of What are the three ways to pass parameters to php?. For more information, please follow other related articles on the PHP Chinese website!