Maison  >  Article  >  développement back-end  >  php 获取全局变量的简单代码_PHP教程

php 获取全局变量的简单代码_PHP教程

WBOY
WBOYoriginal
2016-07-20 11:14:21962parcourir

<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> ?>

主要是用到了key_exists函数与htmlspecialchars函数,关于这二个函数的用法,大家可以参考w3school手册上的介绍。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440302.htmlTechArticle? cleanGlobal( , , = , = ( ( , ) [ ] != [ ] != "" ( ( [ } [ } ? 主要是用到了key_exists函数与htmlspecialchars函数,关于这二个函数的用法,大家可以参考w3s...
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn