PHP扩展库
PECL :: The PHP Extension Community Library
https://pecl.php.net/packages.php
常用的 PHP扩展库
gd2 动态创建图像
xdebug 跟踪 调试和分析PHP程序的运行状况
查看PHP扩展
phpinfo() 输出关于PHP配置的信息
PHP编译选项 启用的扩展 PHP的版本
服务器信息和环境变量
如果编译为一个模块的话
PHP环境变量 操作系统版本信息
path变量 配置选项的本地值和主值
HTTP头和PHP授权信息license
是PHP官方对phpinfo()函数的解释,我们接下来用这个函数来做一个测试。
首先新建一个文件
<?php
phpinfo();
get_loaded_extensions()
PHP解析器里所有编译并加载的模块名
既已经开启的PHP扩展
<?php
get_loaded_extensions();
打印并输入所有已经加载的PHP扩展
检查扩展是否加载
extension_loaded(string name)函数
<?php
extension_loaded("redis");
返回值是bool类型
安装了哪些扩展
命令行模式查看当前
php -m
管理PHP扩展
PHP扩展所在位置
PHP扩展默认的位置在ext文件下
打开PHP配置文件php.ini
找到extension_dir=""
如何开启已经安装但是并未开启的PHP扩展
打开php.ini文件
找到 Dynamic Extensions 模块
只要把分号删掉 重启Apache服务器或者Nginx服务器
extension=要开启的扩展名称
然后重启服务器就可以了
安装PHP扩展
包括Windows和Linux扩展的安装接收
PECL 是PHP扩展的存储库提供已知扩展名和目录下载和开发PHP扩展
windows安装PHP扩展的流程
官方网址下载想要安装的PHP扩展
PHP版本 VC版本 nts/ts x64/x86
解压出很多文件 只需要以.dll结尾的文件
将解压出来的.dll文件放到在php.ini中配置的扩展目录下即可
在php.ini中添加配置信息
extension=php扩展的名称
需要设置配置信息
重启Apache或者Nginx服务器
Linux下安装PHP扩展
下载Linux版本的相对应PHP版本的PHP扩展以.so结尾的文件是直装
把解压的.so文件复制到PHP的扩展目录下 lib/php/extensions/no-debug-non-zts-20131226
修改php.ini配置文件重启服务器
编译安装
以.c或者.h等等这些文件组成的需要编译安装
执行phpize的命令
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/php-config
自动编写配置文件省去手工编写
出现error 是因为没有安装autoconf
centos/redhat下使用下面命令安装:
yum install autoconf
ubuntu下使用下面命令安装
apt-get install autoconf
如果提示错误按照下面的安装
yum lsit php-devel
yum install php-devel.i686
安装完成后重新运 编译和安装
make && make install
在php.ini中写入参数重启服务器
其他扩展信息
phpize是用来扩展PHP扩展模块 通过phpize可以建立PHP的外挂模块
autoconf 生成可以自动配置软件源代码
千年的回眸
PHP Extension curl.
PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.
php.net/manual/en/book.curl.php
千年的回眸
PHP Extension iconv.
iconv — Convert string to requested character encoding
包含了 iconv 字符集转换功能的接口。
可以将一个本地字符集表达的字符串转换成另一种字符集,比如可以是 Unicode 字符集
支持的字符集基于系统上 iconv 的实现
某些系统上 iconv 函数可能无法以预期的那样工作
在这种情况下,安装 » GNU libiconv 库将会是个不错的主意
它最终将会产生更一致的结果。
php.net/manual/zh/book.iconv.php
千年的回眸
PHP Extension mbstring.
处理 PHP 中的多字节编码
一字节仅能够表示 256 种不同的值,即 2 的八次方
多字节字符编码方案是为了在基于字节的常规编码系统中表达超过 256 个字符
操作(trim、split、splice 等等)多字节编码的字符串时,
两个或多个连续字节可能只表达了一个字符,需要使用专门的函数。 否则不能检测多字节字符串的函数应用到这个字符串的时候,以乱码字符串结尾,丢失它原来的意思。
mbstring 提供针对多字节字符串的函数
mbstring 字符编码之间相互进行编码转换
mbstring 基于 Unicode 的编码,类似 UTF-8、UCS-2 及诸多单字节的编码
php.net/manual/zh/book.mbstring.php
千年的回眸
PHP Extension dom.
The DOM extension allows you to operate on XML documents through the DOM API with PHP.
facesoho.com/php/php-xml-dom.html
php.net/manual/en/book.dom.php
千年的回眸
PHP Extension hash.
These functions are intended to work with » mhash. Mhash can be used to create checksums, message digests, message authentication codes, and more.
This is an interface to the mhash library. Mhash supports a wide variety of hash algorithms such as MD5, SHA1, GOST, and many others. For a complete list of supported hashes, refer to the constants page. The general rule is that you can access the hash algorithm from PHP with MHASH_hashname. For example, to access TIGER you use the PHP constant MHASH_TIGER.
php.net/manual/zh/book.mhash.php
千年的回眸
PHP Extension openssl.
This extension binds functions of » OpenSSL library for symmetric and asymmetric encryption and decryption, PBKDF2, PKCS7, PKCS12, X509 and other crypto operations. In addition to that it provides implementation of TLS streams.
OpenSSL offers many features that this module currently doesn't support. Some of these may be added in the future.
PHP7.x 默认就不再附带 mcrypt 扩展,mcrypt 将被 openssl_* 一族函数所替代
php.net/manual/en/book.openssl.php
千年的回眸
PHP Extension xmlwriter.
This is the XMLWriter extension. It wraps the libxml xmlWriter API.
This extension represents a writer that provides a non-cached, forward-only means of generating streams or files containing XML data.
This extension can be used in an object oriented style or a procedural one. Every method documented describes the alternative procedural call.
php.net/manual/zh/intro.xmlwriter.php
千年的回眸
PHP Extension pcre.
正则表达式(兼容 Perl)
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库
执行正规表达式模式匹配时用与Perl 5同样的语法和语义是很有用的
表达式必须用分隔符闭合,比如一个正斜杠(/)
分隔符可以使任意非字母数字,除反斜杠(\)和空字节之外的非空白 ascii 字符
如果分隔符 在表达式中使用,需要使用反斜线进行转义
可以使用 perl 样式的()、 {}、 [] 以及 <> 作为分隔符
结束分隔符后面可以紧跟模式修饰符来影响匹配
PHP也支持使用 POSIX 扩展正则表达式函数 的 POSIX 扩展语法的正则表达式
php.net/manual/zh/reference.pcre.pattern.syntax.php
千年的回眸
PHP Extension json.
实现了JavaScript对象符号(JSON) 数据转换格式
JSON 扩展默认内置并编译进了 PHP
JSON 函数
json_decode — 对 JSON 格式的字符串进行解码
json_encode — 对变量进行 JSON 编码
json_last_error_msg — Returns the error string of the last json_encode() or json_decode() call
json_last_error — 返回最后发生的错误
facesoho.com/php/php-json.html
php.net/manual/zh/book.json.php
千年的回眸
PHP Extension gd.
GD指的是Graphic Device
PHP的GD库用来处理图形的扩展库,通过GD库提供的一系列API,对图像进行处理
创建和处理包括 GIF, PNG, JPEG, WBMP 及 XPM 多种格式的图像。
可以直接将图像数据流输出到浏览器
需要连带 GD 库一起编译 PHP
图像函数来获取下列格式图像的大小: JPEG, GIF, PNG, SWF, TIFF 和 JPEG2000。
exif 相关的函数不需要 GD 库亦可使用
php.net/manual/zh/intro.image.php
千年的回眸
PHP Extension libxml.
These functions/constants are available as of PHP 5.1.0, and the following core extensions rely on this libxml extension: DOM, libxml, SimpleXML, SOAP, WDDX, XSL, XML, XMLReader, XMLRPC 和 XMLWriter.
libxml 函数和常量与 SimpleXML, XSLT 以及 DOM 一起使用
php.net/manual/zh/intro.libxml.php
千年的回眸
PHP Extension bcmath.
大多数编程语言对于浮点型数据格式遵循 IEEE 754 标准,会导致使用浮点数运算会有精度丢失的问题。
PHP提供了 BCMath 库来支持更加精确的计算
Binary Calculator
对于任意精度的数学,PHP提供了支持用字符串表示的任意大小和精度的数字的二进制计算,最多为2147483647-1(或0x7FFFFFFF-1)。
php.net/manual/zh/book.bc.php
千年的回眸
PHP Extension simplexml.
The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators.
php.net/manual/en/intro.simplexml.php
千年的回眸
PHP Extension ctype.
Ctype函数是PHP内置的字符串检测函数
该扩展所提供的函数用来 在当前的区域设定下(参见 setlocale()),一个字符或者字符串 是否仅包含指定类型的字符。
当使用整数作为参数调用这些函数的时候, 这些函数的行为和 C 语言(ctype.h) 中的对应函数一样。
传入了小于 256 的整数参数,它会把这个整数当做 ASCII 码值, 来对应字符是否符合要求(数值的 ASCII 值范围为 0x30-0x39)。
传入的参数介于 -128 和 -1 之间(含 -128 和 -1),它会先将其加上 256,然后再进行
是否是
ctype_alnum
Check for alphanumeric character(s)
只包含[A-Za-z0-9]
ctype_alpha
Check for alphabetic character(s)
只包含[A-Za-z]
ctype_cntrl
Check for control character(s)
检查只包含类是“\n\r\t”之类的字 符控制字符
ctype_digit
Check for numeric character(s)
检查时候是只包含数字字符的字符串(0-9)
ctype_graph
Check for any printable character(s) except space
检查只包含有可以打印出来的字符(除了空格)的字符串
ctype_lower
Check for lowercase character(s)
检查是否所有的字符都是英文字母,并且都是小写的
ctype_print
Check for printable character(s)
检查只包含有可以打印出来的字符的字符串
ctype_punct
Check for any printable character which is not whitespace or an alphanumeric character
检查只包含非数字/字符/空格的可打印出来的字符
ctype_space
Check for whitespace character(s)
检查只包含类是“ ”之类的字符和空格
ctype_upper
Check for uppercase character(s)
检查是否所有的字符都是英文字母,并且都是大写的
ctype_xdigit
Check for character(s) representing a hexadecimal digit
检查16进制的字符串,只能包括 “0123456789abcdef”
php.net/manual/zh/intro.ctype.php
千年的回眸
PHP Extension pdo_mysql
MySQL Functions (PDO_MYSQL)
PDO_MYSQL is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MySQL databases.
php.net/manual/zh/ref.pdo-mysql.php
千年的回眸
PHP Extension zip.
A zip management extension
Zip is an extension to create, modify and read zip files.
pecl.php.net/package/zip
千年的回眸
PHP Extension intl.
PHP intl 是国际化扩展,是ICU 库的一个包装器
ICU(International Component for Unicode/Unicode国际化组件) 是 Unicode 支持、软件国际化、全球化的一个成熟的、广泛应用的库,由 IBM 赞助、支持和使用的,基于"IBM公共许可证",用于支持软件国际化的开源项目
Internationalization extension (further is referred as Intl) is a wrapper for » ICU library, enabling PHP programmers to perform various locale-aware operations including but not limited to formatting, transliteration, encoding conversion, calendar operations, » UCA-conformant collation, locating text boundaries and working with locale identifiers, timezones and graphemes,
It tends to closely follow ICU APIs, so that people having experience working with ICU in either C/C++ or Java could easily use the PHP API. Also, this way ICU documentation would be useful to understand various ICU functions.
php.net/manual/zh/intro.intl.php
千年的回眸
PHP Extension soap.
简单对象访问协议
Simple Object Access Protocol
The SOAP extension can be used to write SOAP Servers and Clients. It supports subsets of SOAP WSDL specifications.
facesoho.com/soap/soap-tutorial.html
php.net/manual/zh/intro.soap.php
千年的回眸
EXtensible Stylesheet Language
The XSL extension
implements the XSL standard, performing » XSLT transformations using the » libxslt library
XSL可扩展样式表语言,用来理解和样式化XML文档,作为基于XML的样式表语言,像CSS基于HTML的样式表语言;是标记语言,指定浏览器应该如何呈现XML文档
www.facesoho.com/xsl/xsl-tutorial.html
www.php.net/manual/zh/intro.xsl.php
千年的回眸
PHP Extension sockets.
Socket扩展是基于流行的BSD sockets,实现了和socket通讯功能的底层接口,它可以和客户端一样当做一个socket服务器
www.php.net/manual/zh/intro.sockets.php