Home  >  Article  >  Backend Development  >  Chapter 6_PHP Array (2)_PHP Tutorial

Chapter 6_PHP Array (2)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:17:16945browse

This essay is a summary of predefined array variables. Through predefined array variables, we can obtain system environment, user dialogue, form data and other information.

 1. Server variable: $_SERVER

Use the foreach statement to print all elements in $_SERVER:

<span 1</span> <?<span php
</span><span 2</span>     <span foreach</span>(<span $_SERVER</span> <span as</span> <span $key</span> => <span $value</span><span ){
</span><span 3</span>         <span echo</span> <span $key</span>.' => '.<span $value</span>.'<br>'<span ;
</span><span 4</span> <span     }
</span><span 5</span> ?>

 2. Environment variables: $_ENV(no output)

3.GET variable: $_GET

<span  1</span> <form action="<?<span $_SERVER</span>['PHP_SELF']?>" method="GET">
<span  2</span>     姓名:<input type="text" name="name" size="15"/>
<span  3</span>     年龄:<input type="text" name="age" size="15"/>
<span  4</span>     爱好:<input type="text" name="hobby" size="15"/>
<span  5</span>     <input type="submit" name="submit" value="提交"/>
<span  6</span> </form>
<span  7</span> <?<span php
</span><span  8</span>     <span if</span>(<span isset</span>(<span $_GET</span>['submit'<span ])){
</span><span  9</span>         <span echo</span> '<p>'<span ;
</span><span 10</span>         <span echo</span> '姓名:'.<span $_GET</span>['name'].'<br>'<span ;
</span><span 11</span>         <span echo</span> '年龄:'.<span $_GET</span>['age'].'<br>'<span ;
</span><span 12</span>         <span echo</span> '爱好:'.<span $_GET</span>['hobby'].'<br>'<span ;
</span><span 13</span> <span     }
</span><span 14</span> ?>

 4.POST variable:$_POST

When transmitting data through POST, the data will not be displayed in the URL, so it is safer than GET. Moreover, there is theoretically no limit to the amount of data transferred through POST.

<span  1</span> <form action="<?<span $_SERVER</span>['PHP_SELF']?>" method="POST">
<span  2</span>     姓名:<input type="text" name="name" size="15"/>
<span  3</span>     年龄:<input type="text" name="age" size="15"/>
<span  4</span>     爱好:<input type="text" name="hobby" size="15"/>
<span  5</span>     <input type="submit" name="submit" value="提交"/>
<span  6</span> </form>
<span  7</span> <?<span php
</span><span  8</span>     <span if</span>(<span isset</span>(<span $_POST</span>['submit'<span ])){
</span><span  9</span>         <span echo</span> '<p>'<span ;
</span><span 10</span>         <span echo</span> '姓名:'.<span $_POST</span>['name'].'<br>'<span ;
</span><span 11</span>         <span echo</span> '年龄:'.<span $_POST</span>['age'].'<br>'<span ;
</span><span 12</span>         <span echo</span> '爱好:'.<span $_POST</span>['hobby'].'<br>'<span ;
</span><span 13</span> <span     }
</span><span 14</span> ?>

5. File upload variable: $_FILES (The code prompt is wrong and the uploaded file cannot be found)

<span  1</span> <form enctype="multipart/form-data"  action="<?=<span $_SERVER</span>['PHP_SELF']?>" method="POST">
<span  2</span>       <input type="hidden" name="MAX_FILE_SIZE" value="104857600" /><!--100M -->
<span  3</span>       上传文件:<input name="upload_file" type="file" size="50"/>
<span  4</span>       <input type="submit" name="submit" value="上传" />    
<span  5</span> </form>
<span  6</span> <?<span php
</span><span  7</span>     <span if</span>(<span isset</span>(<span $_POST</span>['submit'<span ])){
</span><span  8</span>         <span echo</span> <span $_FILES</span>['uplaod_file']['error']==UPLOAD_ERR_OK ? '上传成功!<br>': '上传失败!<br>'<span ;
</span><span  9</span>         <span echo</span> '上传文件名:'.<span $_FILES</span>['upload_file']['name'].'<br>'<span ;
</span><span 10</span>         <span echo</span> '上传文件大小:'.<span $_FILES</span>['upload_file']['size'].'字节<br>'<span ;
</span><span 11</span>         <span echo</span> '临时文件名:'.<span $_FILES</span>['upload_file']['tmp_name'].'<br>'<span ;
</span><span 12</span> <span     }
</span><span 13</span> ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/626575.htmlTechArticleThis essay is a summary of predefined array variables. Through predefined array variables, we can obtain system environment, user dialogue, form data and other information. 1. Server variables: $_SERV...
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