Simple code to get global variables in php_PHP tutorial

WBOY
Release: 2016-07-20 11:14:21
Original
966 people have browsed it

<span  1</span> <?<span php
</span><span  2</span> <span /*</span><span *
</span><span  3</span> <span * 获取全局变量
</span><span  4</span> <span * by www.jbxue.com
</span><span  5</span> <span */</span>
<span  6</span> <span function</span> cleanGlobal(<span $global_array</span>, <span $arg</span>, <span $specialchars</span> = <span true</span>, <span $default</span> = <span null</span><span ) {
</span><span  7</span> 
<span  8</span> <span if</span>(<span key_exists</span>(<span $arg</span>, <span $global_array</span>) && <span $global_array</span>[<span $arg</span>] != <span null</span> && <span $global_array</span>[<span $arg</span>] != ""<span ) {
</span><span  9</span> <span if</span>(<span $specialchars</span><span ) {
</span><span 10</span> <span return</span> <span htmlspecialchars</span>(<span $global_array</span>[<span $arg</span><span ]);
</span><span 11</span> } <span else</span><span  {
</span><span 12</span> <span return</span> <span $global_array</span>[<span $arg</span><span ];
</span><span 13</span> <span }
</span><span 14</span> } <span else</span><span  {
</span><span 15</span> <span return</span> <span $default</span><span ;
</span><span 16</span> <span }
</span><span 17</span> <span }
</span><span 18</span> ?>
Copy after login

The key_exists function and the htmlspecialchars function are mainly used. For the usage of these two functions, you can refer to the introduction in the w3school manual.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440302.htmlTechArticle? cleanGlobal( , , = , = ( ( , ) [ ] != [ ] != "" ( ( [ } [ } ? The key_exists function and the htmlspecialchars function are mainly used. For the usage of these two functions, you can refer to w3s...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template