无需言 做自己 业 ,精于勤 荒于嬉.
- URL 函数 rawurlencode 按照 RFC 3986 对 URL 进行编码
-
发表日期:2021-07-01 08:56:30 | 来源: | 分类:URL 函数
-
示例1
<?php echo '<a href="ftp://user:', rawurlencode('foo @+%/'), '@ftp.example.com/x.txt">'; ?>示例2
<?php echo '<a href="http://example.com/department_list_script/', rawurlencode('sales and marketing/Miami'), '">'; ?>
- SPL 函数 iterator_to_array 将迭代器中的元素拷贝到数组
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
示例1
<?php $iterator = new ArrayIterator(array('recipe'=>'pancakes', 'egg', 'milk', 'flour')); var_dump(iterator_to_array($iterator, true)); var_dump(iterator_to_array($iterator, false)); ?>
- SPL 函数 spl_autoload_call 尝试调用所有已注册的 __autoload() 函数来装载请求类
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
spl_autoload_call
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
spl_autoload_call — 尝试调用所有已注册的 __autoload() 函数来装载请求类
说明
spl_autoload_call(string$class_name): void可以直接在程序中手动调用此函数来使用所有已注册的 __autoload 函数装载类或接口。
参数
-
class_name -
搜索的类名。
返回值
没有返回值。
-
- SPL 函数 class_implements 返回指定的类实现的所有接口。
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
示例1
<?php interface foo { } class bar implements foo { } print_r(class_implements(new bar)); // since PHP 5.1.0 you may also specify the parameter as a stringprint_r(class_implements('bar')); function __autoload($class_name) { require_once $class_name . '.php'; } // use __autoload to load the 'not_loaded' classprint_r(class_implements('not_loaded', true)); ?>
- SPL 函数 spl_autoload_register 注册给定的函数作为 __autoload 的实现
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
示例1
<?php // function __autoload($class) { // include 'classes/' . $class . '.class.php'; // } function my_autoloader($class) { include 'classes/' . $class . '.class.php'; } spl_autoload_register('my_autoloader'); // 或者,自 PHP 5.3.0 起可以使用一个匿名函数spl_autoload_register(function ($class) { include 'classes/' . $class . '.class.php'; } ); ?>示例2
<?php namespace Foobar; class Foo { static public function test($name) { print '[['. $name .']]'; } } spl_autoload_register(__NAMESPACE__ .'\Foo::test'); // 自 PHP 5.3.0 起new InexistentClass; ?>
- SPL 函数 spl_autoload_unregister 注销已注册的 __autoload() 函数
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
spl_autoload_unregister
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
spl_autoload_unregister — 注销已注册的 __autoload() 函数
说明
spl_autoload_unregister(mixed$autoload_function): bool从 autoload 自动装载函数队列中移除指定的函数。如果该函数队列处于激活状态,并且在给定函数注销后该队列变为空,则该函数队列将会变为无效。
如果该函数注销后使得自动装载函数队列无效,即使存在有 __autoload 函数它也不会自动激活。
参数
-
autoload_function -
要注销的自动装载函数。
返回值
成功时返回
true, 或者在失败时返回false。 -
- SPL 函数 spl_classes 返回所有可用的SPL类
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
示例1
<?php print_r(spl_classes()); ?>
- SPL 函数 spl_autoload_extensions 注册并返回 spl_autoload 函数使用的默认文件扩展名
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
示例1
<?php spl_autoload_extensions(".php,.inc"); ?>
- SPL 函数 spl_object_hash 返回指定对象的hash id
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
示例1
<?php $id = spl_object_hash($object); $storage[$id] = $object; ?>
- SPL 函数 spl_object_id Return the integer object handle for given object
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
示例1
<?php $id = spl_object_id($object); $storage[$id] = $object; ?>
- SPL 函数 spl_autoload __autoload()函数的默认实现
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
spl_autoload
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
spl_autoload — __autoload()函数的默认实现
说明
spl_autoload(string$class_name, string$file_extensions= ?): void本函数提供了__autoload()的一个默认实现。如果不使用任何参数调用 spl_autoload_register() 函数,则以后在进行 __autoload() 调用时会自动使用此函数。
参数
-
class_name -
-
file_extensions -
在默认情况下,本函数先将类名转换成小写,再在小写的类名后加上 .inc 或 .php 的扩展名作为文件名,然后在所有的包含路径(include paths)中检查是否存在该文件。
返回值
没有返回值。
-
- SPL 函数 spl_autoload_functions 返回所有已注册的 __autoload() 函数
-
发表日期:2021-07-01 08:56:26 | 来源: | 分类:SPL 函数
-
spl_autoload_functions
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
spl_autoload_functions — 返回所有已注册的 __autoload() 函数
说明
spl_autoload_functions(): array获取所有已注册的 __autoload() 函数。
参数
此函数没有参数。
返回值
包含所有已注册的 __autoload 函数的数组(array)。如果自动装载函数队列未激活,则返回
false。如果没有已注册的函数,则返回一个空数组。
- SPL 函数 class_parents 返回指定类的父类。
-
发表日期:2021-07-01 08:56:25 | 来源: | 分类:SPL 函数
-
示例1
<?php class foo { } class bar extends foo { } print_r(class_parents(new bar)); // since PHP 5.1.0 you may also specify the parameter as a stringprint_r(class_parents('bar')); function __autoload($class_name) { require_once $class_name . '.php'; } // use __autoload to load the 'not_loaded' classprint_r(class_parents('not_loaded', true)); ?>
- SPL 函数 class_uses Return the traits used by the given class
-
发表日期:2021-07-01 08:56:25 | 来源: | 分类:SPL 函数
-
示例1
<?php trait foo { } class bar { use foo; } print_r(class_uses(new bar)); print_r(class_uses('bar')); function __autoload($class_name) { require_once $class_name . '.php'; } // use __autoload to load the 'not_loaded' classprint_r(class_uses('not_loaded', true)); ?>
- SPL 函数 iterator_count 计算迭代器中元素的个数
-
发表日期:2021-07-01 08:56:25 | 来源: | 分类:SPL 函数
-
示例1
<?php $iterator = new ArrayIterator(array('recipe'=>'pancakes', 'egg', 'milk', 'flour')); var_dump(iterator_count($iterator)); ?>
- SPL 函数 iterator_apply 为迭代器中每个元素调用一个用户自定义函数
-
发表日期:2021-07-01 08:56:25 | 来源: | 分类:SPL 函数
-
示例1
<?php function print_caps(Iterator $iterator) { echo strtoupper($iterator->current()) . "\n"; return TRUE; } $it = new ArrayIterator(array("Apples", "Bananas", "Cherries")); iterator_apply($it, "print_caps", array($it)); ?>
- JSON 函数 json_decode 对 JSON 格式的字符串进行解码
-
发表日期:2021-07-01 08:56:20 | 来源: | 分类:JSON 函数
-
示例1
<?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; var_dump(json_decode($json)); var_dump(json_decode($json, true)); ?>示例2
<?php $json = '{"foo-bar": 12345}'; $obj = json_decode($json); print $obj->{'foo-bar'}; // 12345 ?>示例3
<?php // the following strings are valid JavaScript but not valid JSON // the name and value must be enclosed in double quotes // single quotes are not valid $bad_json = "{ 'bar': 'baz' }"; json_decode($bad_json); // null // the name must be enclosed in double quotes $bad_json = '{bar: "baz" }'; json_decode($bad_json); // null// trailing commas are not allowed $bad_json = '{bar: "baz", }'; json_decode($bad_json); // null ?>示例4
<?php // Encode the data. $json = json_encode(array(1 => array('English' => array('One','January'),'French' => array('Une','Janvier')))); // Define the errors. $constants = get_defined_constants(true); $json_errors = array(); foreach ($constants["json"] as $name => $value) { if (!strncmp($name, "JSON_ERROR_", 11)) { $json_errors[$value] = $name; } } // Show the errors for different depths. foreach (range(4, 3, -1) as $depth) { var_dump(json_decode($json, true, $depth)); echo 'Last error: ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL; } ?>示例5
<?php $json = '{ "number": 12345678901234567890} '; var_dump(json_decode($json)); var_dump(json_decode($json, false, 512, JSON_BIGINT_AS_STRING)); ?>
- JSON 函数 json_last_error_msg Returns the error string of the last json_encode() or json_decode() call
-
发表日期:2021-07-01 08:56:20 | 来源: | 分类:JSON 函数
-
json_last_error_msg
(PHP 5 >= 5.5.0, PHP 7, PHP 8)
json_last_error_msg — Returns the error string of the last json_encode() or json_decode() call
说明
json_last_error_msg(): stringReturns the error string of the last json_encode() or json_decode() call, which did not specify
JSON_THROW_ON_ERROR.参数
此函数没有参数。
返回值
Returns the error message on success, or
"No error"if no error has occurred.
- JSON 函数 json_encode 对变量进行 JSON 编码
-
发表日期:2021-07-01 08:56:20 | 来源: | 分类:JSON 函数
-
示例1
<?php $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_encode($arr); ?>示例2
<?php $a = array('<foo>',"'bar'",'"baz"','&blong&', "\xc3\xa9"); echo "Normal: ", json_encode($a), "\n"; echo "Tags: ", json_encode($a, JSON_HEX_TAG), "\n"; echo "Apos: ", json_encode($a, JSON_HEX_APOS), "\n"; echo "Quot: ", json_encode($a, JSON_HEX_QUOT), "\n"; echo "Amp: ", json_encode($a, JSON_HEX_AMP), "\n"; echo "Unicode: ", json_encode($a, JSON_UNESCAPED_UNICODE), "\n"; echo "All: ", json_encode($a, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE), "\n\n"; $b = array(); echo "Empty array output as array: ", json_encode($b), "\n"; echo "Empty array output as object: ", json_encode($b, JSON_FORCE_OBJECT), "\n\n"; $c = array(array(1,2,3)); echo "Non-associative array output as array: ", json_encode($c), "\n"; echo "Non-associative array output as object: ", json_encode($c, JSON_FORCE_OBJECT), "\n\n"; $d = array('foo' => 'bar', 'baz' => 'long'); echo "Associative array always output as object: ", json_encode($d), "\n"; echo "Associative array always output as object: ", json_encode($d, JSON_FORCE_OBJECT), "\n\n"; ?>示例3
<?php echo "Strings representing numbers automatically turned into numbers".PHP_EOL; $numbers = array('+123123', '-123123', '1.2e3', '0.00001'); var_dump( $numbers, json_encode($numbers, JSON_NUMERIC_CHECK)); echo "Strings containing improperly formatted numbers".PHP_EOL; $strings = array('+a33123456789', 'a123'); var_dump( $strings, json_encode($strings, JSON_NUMERIC_CHECK)); ?>示例4
<?php echo "连续数组".PHP_EOL; $sequential = array("foo", "bar", "baz", "blong"); var_dump( $sequential, json_encode($sequential)); echo PHP_EOL."非连续数组".PHP_EOL; $nonsequential = array(1=>"foo", 2=>"bar", 3=>"baz", 4=>"blong"); var_dump( $nonsequential, json_encode($nonsequential)); echo PHP_EOL."删除一个连续数组值的方式产生的非连续数组".PHP_EOL; unset($sequential[1]); var_dump( $sequential, json_encode($sequential)); ?>示例5
<?php var_dump(json_encode(12.0, JSON_PRESERVE_ZERO_FRACTION)); var_dump(json_encode(12.0)); ?>
- JSON 函数 json_last_error 返回最后发生的错误
-
发表日期:2021-07-01 08:56:20 | 来源: | 分类:JSON 函数
-
示例1
<?php // 一个有效的 json 字符串$json[] = '{ "Organization": "PHP Documentation Team"} '; // 一个无效的 json 字符串会导致一个语法错误,在这个例子里我们使用 ' 代替了 " 作为引号$json[] = "{ 'Organization': 'PHP Documentation Team'} "; foreach ($json as $string) { echo 'Decoding: ' . $string; json_decode($string); switch (json_last_error()) { case JSON_ERROR_NONE: echo ' - No errors'; break; case JSON_ERROR_DEPTH: echo ' - Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: echo ' - Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: echo ' - Unexpected control character found'; break; case JSON_ERROR_SYNTAX: echo ' - Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: echo ' - Unknown error'; break; } echo PHP_EOL; } ?>示例2
<?php // 无效的 UTF8 序列$text = "\xB1\x31"; $json = json_encode($text); $error = json_last_error(); var_dump($json, $error === JSON_ERROR_UTF8); ?>
- 前端开发(1)
- 数据库(0)
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)
- JAVA(0)
- Android(0)
- Linux(0)
- AI大模型(9)
- 其他(0)
宁公网安备 64010402001209号