layout | title | date | author | desc | in_head |
---|---|---|---|---|---|
post
|
PHP几个牛逼的函数
|
2018-6-28- 10:00:02 +0800
|
南丞
|
PHP牛逼的函数介绍
|
<style> .article-content p{ text-indent: 2em; line-height: 1.75rem; }</style>
|
PHP几个牛逼的函数
-
get_included_files() 和 get_required_files()
返回被 include 和 require 文件名的 array
<?php
include './1.php';
include './i.php';
require './2.php';
$files = get_included_files();
var_dump($files);
$files_list = get_include_path();
var_dump($files_list);
var_dump(get_required_files());
结果:
D:\phpStudy\WWW\test.php:7:
array (size=4)
0 => string 'D:\phpStudy\WWW\test.php' (length=24)
1 => string 'D:\phpStudy\WWW\1.php' (length=21)
2 => string 'D:\phpStudy\WWW\i.php' (length=21)
3 => string 'D:\phpStudy\WWW\2.php' (length=21)
D:\phpStudy\WWW\test.php:9:string '.;C:\php\pear' (length=13)
D:\phpStudy\WWW\test.php:10:
array (size=4)
0 => string 'D:\phpStudy\WWW\test.php' (length=24)
1 => string 'D:\phpStudy\WWW\1.php' (length=21)
2 => string 'D:\phpStudy\WWW\i.php' (length=21)
3 => string 'D:\phpStudy\WWW\2.php' (length=21)
-
php_check_syntax()
用来检查特定文件中的PHP语法是否正确。
<?php
$error_message = "";
$filename = "./php_script.php";
if(!php_check_syntax($filename, &$error_message)) {
echo "Errors were found in the file $filename: $error_message";
} else {
echo "The file $filename contained no syntax errors";
}
?>
- highlight_string() 和 show_source(),php_strip_whitespace()
把PHP代码显示到页面上时,highlight_string()函数就会非常有用,它可以用内置定义的语法高亮颜色把你提供的PHP代码高亮显示。
<?php
highlight_string(' <?php phpinfo(); ?>');
show_source("php_script.php");
echo php_strip_whitespace("php_script.php");
?>
- str_word_count()
这个函数可以用来统计字符串中单词的数量。
<?php
echo str_word_count("Hello How Are You!");
- get_defined_vars()
这个函数在代码调试时十分重要,它会返回一个包括所有已定义的变量的多维数组。
<?php
print_r(get_defined_vars());
- checkdate()
验证一个格里高里日期
<?php
var_dump(checkdate(12, 31, 2000));
var_dump(checkdate(2, 29, 2001));