search
HomeBackend DevelopmentPHP ProblemWhat 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.

What are the three ways to pass parameters to php?

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(&#39;a:b:&#39;);
print_r($param_arr);

##3

. Input data through the user

<?php /**
 * 提示用户输入,类似Python
 */
fwrite(STDOUT,&#39;please input:&#39;);
echo &#39;your input is:&#39;.fgets(STDIN);
The user’s input cannot be empty

<?php /**
 * 提示用户输入,类似Python
 */

$fs = true;

do{
    if($fs){
        fwrite(STDOUT,&#39;请输入您的博客名:&#39;);
        $fs = false;
    }else{
        fwrite(STDOUT,&#39;抱歉,博客名不能为空,请重新输入您的博客名:&#39;);
    }

$name = trim(fgets(STDIN));

}while(!$name);

echo &#39;您输入的信息是:&#39;.$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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Hot Topics