php用ini_get获取php.ini里变量值的方法_PHP
本文实例讲述了php用ini_get获取php.ini里变量值的方法。分享给大家供大家参考。具体分析如下:
要得到php.ini里的变量值,当然,你可以用phpinfo();来得到所有php配置信息,但如果要想得到某个变量值的话,你又要怎样获取呢?
php里提供一个获取php.ini里的变量值的函数:ini_get()
ini_get()的用法非常简单,下面通过实例说明它是如何使用的。
语法:
string ini_get ( string varname )
返回值如果为布尔型则为0或1
实例:
<?php /* 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"; echo 'post_max_size in bytes = ' . return_bytes(ini_get('post_max_size')); function return_bytes($val) { $val = trim($val); $last = strtolower($val[strlen($val)-1]); switch($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } ?>
上述代码的运行结果类似如下:
display_errors = 1 register_globals = 0 post_max_size = 8M post_max_size+1 = 9 post_max_size in bytes = 8388608
如果想获取整个php.ini里的变量值,我们可以用ini_get的加强函数 ini_get_all()。
ini_get_all()函数以数组的形式返回整个php的环境变量,用法也很简单。
实例一:
<?php print_r(ini_get_all("pcre")); print_r(ini_get_all()); ?>
上述代码的运行结果类似如下:
Array ( [pcre.backtrack_limit] => Array ( [global_value] => 100000 [local_value] => 100000 [access] => 7 ) [pcre.recursion_limit] => Array ( [global_value] => 100000 [local_value] => 100000 [access] => 7 ) ) Array ( [allow_call_time_pass_reference] => Array ( [global_value] => 0 [local_value] => 0 [access] => 6 ) [allow_url_fopen] => Array ( [global_value] => 1 [local_value] => 1 [access] => 4 ) ... )
实例二:
<?php print_r(ini_get_all("pcre", false)); // Added in PHP 5.3.0 print_r(ini_get_all(null, false)); // Added in PHP 5.3.0 ?>
输出结果类似如下:
Array ( [pcre.backtrack_limit] => 100000 [pcre.recursion_limit] => 100000 ) Array ( [allow_call_time_pass_reference] => 0 [allow_url_fopen] => 1 ... )
与ini_get()相对的函数是ini_set(),ini_set具有更改php.ini设置的功能。例如当某脚本运行超时时,可以设置其最大执行时间。
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
