PHP的幾個設定檔函數_PHP教程

來源:互聯網
上載者:User
以前一直沒注重,今天聽同事講起,馬上看看,功能強大。
php的配置函數就是幾個ini_*的函數,主要是針對設定檔的操作,其實就四個函數:ini_get、ini_set、ini_get_all、ini_restore。個人感覺最有用的就是ini_set和ini_get。
* ini_get():擷取設定檔的選項值
這個函數相信很多人都使過,就是擷取設定檔中某一個選項的值,假如是true值就返回1,假如是false值就返回0,字串就返回字串。
比如手冊中的例子:
/*
Our php.ini contains the following settings:
display_errors = On
register_globals = Off
post_max_size = 8M
*/
echo 'display_errors = ' . ini_get('display_errors') . "n"; //顯示錯誤是否開啟
echo 'register_globals = ' . ini_get('register_globals') . "n";//全域變數是否開啟
echo 'post_max_size = ' . ini_get('post_max_size') . "n";//最多能提交的檔案大小
echo 'post_max_size 1 = ' . (ini_get('post_max_size') 1) . "n";
?>
輸出:
display_errors = 1
register_globals = 0
post_max_size = 8M
post_max_size 1 = 9

這個函數主要是為了擷取設定檔,可以方便你很多操作。比如你想操作字串過濾,但是又不清楚magic_quotes_gpc有沒有開啟,所以你就可以這樣寫一個函數:
/* 字串過濾函數 */
function stringFilter($str)
{
if (ini_get('magic_quotes_gpc)') {
return $str;
} else {
return addslashes($str);
}
}
當然,假如你無法知道你的全域變數是否開啟,也可以定製這樣的函數:
/* 變數檢測函數 */
function getGetVar($var)
{
if (ini_set('register_gobals')) {
return $var;
} else {
return $_GET['var'];


http://www.bkjia.com/PHPjc/445532.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445532.htmlTechArticle以前一直沒注重,今天聽同事講起,馬上看看,功能強大。 php的配置函數就是幾個ini_*的函數,主要是針對設定檔的操作,其實就四個函...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.