Home > Article > Backend Development > Introduction to the specific usage of PHP configuration function ini_get()_PHP tutorial
Output:
PHP configuration function ini_get() is mainly used to obtain the configuration file, which can be a lot more convenient for you operate. For example, you want to operate string filtering, but you don’t know whether magic_quotes_gpc is turned on, so you can write a function like this:
<ol class="dp-xml"> <li class="alt"><span><span>/* 字符串过滤函数 */ </span></span></li> <li><span>function stringFilter($str) </span></li> <li class="alt"><span>{ </span></li> <li><span>if (ini_get(’magic_quotes_gpc)’) </span></li> <li><span>{ </span></li> <li class="alt"><span>return $str; </span></li> <li><span>} </span></li> <li><span>else { </span></li> <li class="alt"><span>return addslashes($str); </span></li> <li><span>} </span></li> <li class="alt"><span>} </span></li> </ol>
Of course, if You have no way of knowing whether your global variables are open, or you can customize a function like this:
<ol class="dp-xml"> <li class="alt"><span><span>/* 变量检测函数 */ </span></span></li> <li><span>function getGetVar($var) </span></li> <li class="alt"><span>{ </span></li> <li><span>if (ini_set(’register_gobals’))</span></li> <li><span>{ </span></li> <li class="alt"><span>return $var; </span></li> <li><span>} </span></li> <li><span>else { </span></li> <li class="alt"><span>return $_GET['var']; </span></li> <li><span>} </span></li> <li class="alt"><span>} </span></li> </ol>
Of course, you can do it with the PHP configuration function ini_get() There are many uses, you can slowly experience them yourself.