PHP函数库分类三十四.docx
《PHP函数库分类三十四.docx》由会员分享,可在线阅读,更多相关《PHP函数库分类三十四.docx(11页珍藏版)》请在冰豆网上搜索。
![PHP函数库分类三十四.docx](https://file1.bdocx.com/fileroot1/2023-7/9/4ea647ca-8bf3-46f3-b8b8-da9f3e7dd3c7/4ea647ca-8bf3-46f3-b8b8-da9f3e7dd3c71.gif)
PHP函数库分类三十四
PHP函数库分类三十四
10.PHP选项/信息函数列表6
·phpcredits -PrintsoutthecreditsforPHP
phpcredits
(PHP4,PHP5)
phpcredits — PrintsoutthecreditsforPHP
说明
bool phpcredits ([ int $flag =CREDITS_ALL ])
ThisfunctionprintsoutthecreditslistingthePHPdevelopers,modules,etc.ItgeneratestheappropriateHTMLcodestoinserttheinformationinapage.
参数
flag
Togenerateacustomcreditspage,youmaywanttousethe flag parameter.
Pre-defined phpcredits() flags
name
description
CREDITS_ALL
Allthecredits,equivalenttousing:
CREDITS_DOCS +CREDITS_GENERAL + CREDITS_GROUP + CREDITS_MODULES +CREDITS_FULLPAGE.Itgeneratesacompletestand-aloneHTMLpagewiththeappropriatetags.
CREDITS_DOCS
Thecreditsforthedocumentationteam
CREDITS_FULLPAGE
Usuallyusedincombinationwiththeotherflags.Indicatesthatacompletestand-aloneHTMLpageneedstobeprintedincludingtheinformationindicatedbytheotherflags.
CREDITS_GENERAL
Generalcredits:
Languagedesignandconcept,PHPauthorsandSAPImodule.
CREDITS_GROUP
Alistofthecoredevelopers
CREDITS_MODULES
AlistoftheextensionmodulesforPHP,andtheirauthors
CREDITS_SAPI
AlistoftheserverAPImodulesforPHP,andtheirauthors
返回值
成功时返回 TRUE,或者在失败时返回 FALSE.
范例
Example#1Printsthegeneralcredits
php
phpcredits(CREDITS_GENERAL);
?
>
Example#2Printsthecoredevelopersandthedocumentationgroup
php
phpcredits(CREDITS_GROUP | CREDITS_DOCS | CREDITS_FULLPAGE);
?
>
Example#3Printingallthecredits
My credits page
php
// some code of your own
phpcredits(CREDITS_ALL - CREDITS_FULLPAGE);
// some more code
?
>
·phpversion -GetsthecurrentPHPversion
phpversion
(PHP4,PHP5)
phpversion — GetsthecurrentPHPversion
说明
string phpversion ([ string $extension ])
ReturnsastringcontainingtheversionofthecurrentlyrunningPHPparserorextension.
参数
extension
Anoptionalextensionname.
返回值
Iftheoptional extension parameterisspecified, phpversion() returnstheversionofthatextension,or FALSE ifthereisnoversioninformationassociatedortheextensionisn'tenabled.
范例
Example#1 phpversion() example
php
// prints e.g. 'Current PHP version:
4.1.1'
echo 'Current PHP version:
' . phpversion();
// prints e.g. '2.0' or nothing if the extension isn't enabled
echo phpversion('tidy');
?
>
Example#2 PHP_VERSION_ID exampleandusage
php
// PHP_VERSION_ID is available as of PHP 5.2.7, if our
// version is lower than that, then emulate it
if (!
defined('PHP_VERSION_ID')) {
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
// PHP_VERSION_ID is defined as a number, where the higher the number
// is, the newer a PHP version is used. It's defined as used in the above
// expression:
//
// $version_id = $major_version * 10000 + $minor_version * 100 + $release_version;
//
// Now with PHP_VERSION_ID we can check for features this PHP version
// may have, this doesn't require to use version_compare() everytime
// you check if the current PHP version may not support a feature.
//
// For example, we may here define the PHP_VERSION_* constants thats
// not available in versions prior to 5.2.7
if (PHP_VERSION_ID < 50207) {
define('PHP_MAJOR_VERSION', $version[0]);
define('PHP_MINOR_VERSION', $version[1]);
define('PHP_RELEASE_VERSION', $version[2]);
// and so on, ...
}
?
>
注释
Note:
Thisinformationisalsoavailableinthepredefinedconstant PHP_VERSION.Moreversioninginformationisavailableusingthe PHP_VERSION_* constants.
·php_ini_loaded_file -Retrieveapathtotheloadedphp.inifile
php_ini_loaded_file
(PHP5>=5.2.4)
php_ini_loaded_file — Retrieveapathtotheloadedphp.inifile
说明
string php_ini_loaded_file ( void )
Checkifa php.ini fileisloaded,andretrieveitspath.
参数
此函数没有参数。
返回值
Theloaded php.ini path,or FALSE ifoneisnotloaded.
范例
Example#1 php_ini_loaded_file() example
php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini:
' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?
>
以上例程的输出类似于:
Loadedphp.ini:
/usr/local/php/php.ini
·php_ini_scanned_files -Returnalistof.inifilesparsedfromtheadditionalinidir
php_ini_scanned_files
(PHP4>=4.3.0,PHP5)
php_ini_scanned_files — Returnalistof.inifilesparsedfromtheadditionalinidir
说明
string php_ini_scanned_files ( void )
php_ini_scanned_files() returnsacomma-separatedlistofconfigurationfilesparsedafter php.ini.Thesefilesarefoundinadirectorydefinedbythe --with-config-file-scan-dir optionwhichissetduringcompilation.
Thereturnedconfigurationfilesalsoincludethepathasdeclaredinthe --with-config-file-scan-dir option.
返回值
Returnsacomma-separatedstringof.inifilesonsuccess.Eachcommaisfollowedbyanewline.Ifthedirective --with-config-file-scan-dir wasn'tset,FALSE isreturned.Ifitwassetandthedirectorywasempty,anemptystringisreturned.Ifafileisunrecognizable,thefilewillstillmakeitintothereturnedstringbutaPHPerrorwillalsoresult.ThisPHPerrorwillbeseenbothatcompiletimeandwhileusing php_ini_scanned_files().
范例
Example#1Asimpleexampletolistthereturnedinifiles
php
if ($filelist = php_ini_scanned_files()) {
if (strlen($filelist) > 0) {
$files = explode(',', $filelist);
foreach ($files as $file) {
echo "
" . trim($file) . "";
}
}
}
?
>
·php_logo_guid -Getsthelogoguid
php_logo_guid
(PHP4,PHP5)
php_logo_guid — Getsthelogoguid
说明
string php_logo_guid ( void )
ThisfunctionreturnstheIDwhichcanbeusedtodisplaythePHPlogousingthebuilt-inimage.Logoisdisplayedonlyifexpose_phpisOn.
返回值
Returns PHPE9568F34-D428-11d2-A769-00AA001ACF42.
范例
Example#1 php_logo_guid() example
php
echo '![]()
'?
=' . php_logo_guid() . '" alt="PHP Logo !
" />';
?
>
·php_sapi_name -ReturnsthetypeofinterfacebetweenwebserverandPHP
php_sapi_name
(PHP4>=4.0.1,PHP5)
php_sapi_name — ReturnsthetypeofinterfacebetweenwebserverandPHP
说明
string php_sapi_name ( void )
Returnsalowercasestringthatdescribesthetypeofinterface(theServerAPI,SAPI)thatPHPisusing.Forexample,inCLIPHPthisstringwillbe"cli"whereaswithApacheitmayhaveseveraldifferentvaluesdependingontheexactSAPIused.Possiblevaluesarelistedbelow.
返回值
Returnstheinterfacetype,asalowercasestring.
Althoughnotexhaustive,thepossiblereturnvaluesinclude aolserver, apache,apache2filter, apache2handler, caudium, cgi (untilPHP5.3), cgi-fcgi, cli,continuity, embed, isapi, litespeed, milter, nsapi, phttpd, pi3web, roxen, thttpd,tux,and webjames.
范例
Example#1 php_sapi_name() example
Thisexamplechecksforthesubstring cgi becauseitmayalsobe cgi-fcgi.
php
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "You are using CGI PHP";
} else {
echo "You are not using CGI PHP";
}
?
>
注释
Note:
Analternativeapproach
ThePHPconstant PHP_SAPI hasthesamevalueas php_sapi_name().
Tip
Apotentialgotcha
Thedefined SAPI maynotbeobvious,becauseforexampleinsteadof apache itmaybedefinedas apache2handler or apache2filter.
·php_uname -ReturnsinformationabouttheoperatingsystemPHPisrunningon
php_uname
(PHP4>=4.0.2,PHP5)
php_uname — ReturnsinformationabouttheoperatingsystemPHPisrunningon
说明
string php_uname ([ string $mode ="a" ])
php_uname() returnsadescriptionoftheoperatingsystemPHPisrunningon.Thisisthesamestringyouseeattheverytopofthe phpinfo() output.Forthenameofjusttheoperatingsystem,considerusingthe PHP_OS constant,butkeepinmindthisconstantwillcontaintheoperatingsystemPHPwas built on.
OnsomeolderUNIXplatforms,itmaynotbeabletodeterminethecurrentOSinformationinwhichcaseitwillreverttodisplayingtheOSPHPwasbuilton.Thiswillonlyhappenifyouruname()librarycalleitherdoesn'texistordoesn'twork.
参数
mode
mode isasinglecharacterthatdefineswhatinformationisreturned:
∙'a':
Thisisthedefault.Containsallmodesinthesequence "snrvm".
∙'s':
Operatingsystemname.eg. FreeBSD.
∙'n':
Hostname.eg. .
∙'r':
Releasename.eg. 5.1.2-RELEASE.
∙'v':
Versioninformation.Variesalotbetweenoperatingsystems.
∙'m':
Machinetype.eg. i386.
返回值
Returnsthedescription,asastring.
范例
Example#1Some php_uname() examples
php
echo php_uname();
echo PHP_OS;
/* Some possible outputs:
Linux localhost 2.4.21-0.13mdk #1 Fri Mar 14 15:
08:
06 EST 2003 i686
Linux
FreeBSD localhost 3.2-RELEASE #15:
Mon Dec 17 08:
46:
02 GMT 2001
FreeBSD
Windows NT XN1 5.1 build 2600
WINNT
*/
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
echo 'This is a server using Windows!
';
} else {
echo 'This is a server not using Windows!
';
}
?
>
Therearealsosomerelated PredefinedPHPconstants thatmaycomeinhandy,forexample:
Example#2AfewOSrelatedconstantexamples
php
// *nix
echo DIRECTORY_SEPARATOR; // /
echo PHP_SHLIB_SUFFIX; // so
echo PATH_SEPARATOR; // :
// Win*
echo DIRECTORY_SEPARATOR; //
echo PHP_SHLIB_SUFFIX; // dll
echo PATH_SEPARATOR; // ;
?
>
·putenv -Setsthevalueofanenvironmentvariable
putenv
(PHP4,PHP5)
putenv — Setsthevalueofanenvironmentvariable
说明
bool putenv ( string $setting )
Adds setting totheserverenvironment.Theenvironmentvariablewillonlyexistforthedurationofthecurrentrequest.Attheendoftherequesttheenvironmentisrest