php ini_get,ini_get - [ php中文手册 ] - 在线原生手册 - php中文网
用户评论:
[#1]
bishop at php dot net [2015-09-02 19:52:28]
In a similar vein, converting flags to booleans proper:
{
static$map= array ('on'=>true,'true'=>true,'off'=>false,'false'=>false);
return @($map[strtolower($val)] ?: (bool)$val);
}?>
If you're using PHP >= 7, consider replacing ?: with ?? and removing the @ silencer.
[#2]
bishop@php [2015-09-02 19:37:00]
Yet another implementation of return_bytes:
{assert('1 === preg_match("/^\d+([kmg])?$/i", $val)');
static$map= array ('k'=>1024,'m'=>1048576,'g'=>1073741824);
return (int)$val* @($map[strtolower(substr($val, -1))] ?:1);
}?>
If you're using PHP >= 7, you might replace ?: with ?? to avoid the use of the @ silencer.
[#3]
Ivo Mandalski [2011-11-15 08:27:52]
This version of return_bytes takes care of the MB, GB, KB cases along with the M,G,K ones.
Hope this is helpful!
{
if(empty($val))return0;$val=trim($val);preg_match('#([0-9]+)[\s]*([a-z]+)#i',$val,$matches);$last='';
if(isset($matches[2])){$last=$matches[2];
}
if(isset($matches[1])){$val= (int)$matches[1];
}
switch (strtolower($last))
{
case'g':
case'gb':$val*=1024;
case'm':
case'mb':$val*=1024;
case'k':
case'kb':$val*=1024;
}
return (int)$val;
}?>
[#4]
Stas Trefilov, OpteamIS [2010-03-26 10:08:06]
another version of return_bytes which returns faster and does not use multiple multiplications (sorry:). even if it is resolved at compile time it is not a good practice;
no local variables are allocated;
the trim() is omitted (php already trimmed values when reading php.ini file);
strtolower() is replaced by second case which wins us one more function call for the price of doubling the number of cases to process (may slower the worst-case scenario when ariving to default: takes six comparisons instead of three comparisons and a function call);
cases are ordered by most frequent goes first (uppercase M-values being the default sizes);
specs say we must handle integer sizes so float values are converted to integers and 0.8G becomes 0;
'Gb', 'Mb', 'Kb' shorthand byte options are not implemented since are not in specs, see
http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
{
switch (substr($size_str, -1))
{
case'M': case'm': return (int)$size_str*1048576;
case'K': case'k': return (int)$size_str*1024;
case'G': case'g': return (int)$size_str*1073741824;
default: return$size_str;
}
}?>
[#5]
nicolas dot grekas+php at gmail dot com [2009-08-19 10:51:14]
Here is how to accurately test for boolean php.ini values:
{$b=ini_get($a);
switch (strtolower($b))
{
case'on':
case'yes':
case'true':
return'assert.active'!==$a;
case'stdout':
case'stderr':
return'display_errors'===$a;
default:
return (bool) (int)$b;
}
}?>
[#6]
peter [2008-07-29 14:25:11]
The above example function called return_bytes() assumes that ini_get('upload_max_filesize') delivers only one letter at the end. As I've seen 'Mb' and things like that, I'd suggest to change the $last = ... part into $last = strtolower(substr($val,strlen($val/1),1)).
I'd call it $unit then.
[#7]
filh at filh dot org [2005-11-21 06:24:55]
Concerning the value retourned, it depends on how you set it.
I had the problem with horde-3 which test the safe_mode value.
THan :
- if you set the value with php_admin_value safe_mode Off (or On) ini_get returns the string
- if you set the value with php_admin_flag safe_mode Off (or On) ini_get returns the boolean.
[#8]
david dot tulloh at infaze dot com dot au [2005-06-21 19:01:37]
You can set custom entries in the ini file to provide globals such as database details.
However these must be retrieved with get_cfg_var, ini_get won't work.
[#9]
Der Graph [2004-08-16 11:59:05]
It might be useful for included scripts that include other files to extend the 'include_path' variable:
Sometimes, it may also be useful to store the current 'include_path' in a variable, overwrite it, include, and then restore the old 'include_path'.
php ini_get,ini_get - [ php中文手册 ] - 在线原生手册 - php中文网相关推荐
- ahri8.php,文件上传处理 - [ php中文手册 ] - 在线原生手册 - php中文网
用户评论: [#1] bayu dot dp2303 at gmail dot com [2015-06-17 12:12:39] $rx = gmdate("H",time()+ ...
- php gui中文手册,git gui - [ Git中文开发手册 ] - 在线原生手册 - php中文网
名称 git-gui - Git 的便携式图形界面 概要 git gui [] [arguments] 描述 基于 Tcl / Tk 的 Git 图形用户界面.git gui侧重于允许用户通过新的 ...
- php recordarray,Array 数组 - [ php中文手册 ] - 在线原生手册 - php中文网
用户评论: [#1] florenxe [2015-10-07 18:53:45] //a nice little way to print leap years using array for ($ ...
- php gridview,GridView - [ Android中文手册 ] - 在线原生手册 - php中文网
GridView 版本:Android 2.2 r1 public final class GridView extendsAbsListView java.lang.Object android.v ...
- c语言fsetpos是什么,fsetpos - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义int fsetpos(FILE * stream,const fpos_t * pos); stream根据指向的值设置文件流的文件位置指示符和多字节解析状态(如果有)pos. 除了建 ...
- c语言中mw shl code,cacoshl - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义float complex cacoshf( float complex z );(1)(since C99) double complex cacosh( dou ...
- php vprintf,vprintf - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
格式-指向以空字符结尾的字符串的指针,指定如何解释数据.格式字符串由普通的多字节字符(%除外)组成,它们被原样复制到输出流和转换规范中.每个转换规范具有以下格式:介绍%字符(可选)一个或多个标志,用于 ...
- cbrt c语音_isgraph - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义int isgraph(int ch); 检查给定字符是否具有图形表示形式,即它是数字(0123456789),大写字母(ABCDEFGHIJKLMNOPQRSTUVWXYZ),小写字母 ...
- c语言L文件,frexpl - [ C语言中文开发手册 ] - 在线原生手册 - php中文网
在头文件中定义float frexpf(float arg,int * exp);(1)(自C99以来) double frexp(double arg,int * exp);(2) long dou ...
最新文章
- This Android SDK requires Android Developer Toolkit version 22.6.2 or above.
- python一个月能学成嘛-一个月可以学好基础的Python吗?
- ORA-00257: archiver error. Connect internal only, until freed
- 64 os 驱动签名
- python实现父类继承_Python多继承用super调用父类方法?
- 稿定设计怎么免费去水印
- 深入理解5种IO模型
- 不重启修改计算机名称,批处理不重启快速修改计算机名
- filestream_SQL Server FILESTREAM内部概述
- linux中用shell获取昨天、明天或多天前的日期
- 缓存框架 EhCache 使用 4
- 百度推广怎么调整计算机优先,百度竞价优化关于帐户层级的一些设置方法与技巧...
- ITIL 4 Foundation 思维导图笔记整理
- chromecast投屏_利用谷歌Chromecast,3个简单的步骤教你将手机投屏到电视上
- 计算机数制与转换教案,《数制转换》教案
- Nvidia30系显卡+Windows系统的CUDA 11安装100%成功教程
- 一笔画:五环,python-turtle。画圆圈
- Go是Google的语言,而不是我们的语言
- java中hashmap遍历的几种方法
- 深度学习分类分到同一个类